Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question Echo, Print or how to echo to screen?

    I found this useful piece of code here;
    I was wondering how to print what I need to print on the screen?
    PHP Code:
    <?php
    $sql 
    "SELECT * FROM Photos";
    $sql1 mysql_query($sql) or die(mysql_error());
    if(
    mysql_num_rows($sql1) > 0)
    {
        
    $i 0;
        echo 
    '<table border="1">'."\n";
        while(
    $result=mysql_fetch_array($sql1))
        {
            if(
    $i == 0) echo '<tr>'."\n";
            echo 
    '<th scope="col"><img src="photos/'.$result['Filename'].'"></th>'."\n";
            
    $i++;
            if(
    $i == 0) echo '</tr>'."\n";
        }
        echo 
    '</table>';
    }
    ?>
    My needs are here:
    PHP Code:
    <?php
    $sql 
    $query_rsnav1;
    $sql1 mysql_query($sql) or die(mysql_error());
    if(
    mysql_num_rows($sql1) > 0)
    {
        
    $i 0;
        echo 
    '<table border="0">'."\n";
        while(
    $result=mysql_fetch_array($sql1))
        {
        if(
    $i == 1) echo '<tr>'."\n";

    //start problem area

    echo '<th scope="col"><a href="?catid=<?php echo $_GET['catid']; ?>&img=<?php echo $row_rsnav1['image']; ?>&navid=<?php echo $row_rsnav1['intid']; ?>"><img src="uploads/<?php echo $row_rsnav1['thumb']; ?>" alt="" width="100" border="0"/></a></th>'."\n";

    //end problem area

        
    $i++;
        if(
    $i == 1) echo '</tr>'."\n";
        }
        echo 
    '</table>';
    }
    ?>
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I don't understand you're problem, you'll need to clarify. I'm guessing you just need to change this line:
    PHP Code:
    //start problem area

    echo '<th scope="col"><a href="?catid=' $_GET['catid'] . '&img=' $row_rsnav1['image'] . '&navid=' $row_rsnav1['intid'] . '"><img src="uploads/' $row_rsnav1['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n"
    <?php echo does not belone with a part of a string unless you are filtering it through eval.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    student101 (07-15-2008)

  • #3
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    That works, as in displaying the images using ?catid=1 but it fills the entire screen with duplicates instead of the one row.

    So the same image fills up an entire row, then the next and so on... This is incorrect as there are only 8 images to display, preferably in a horizontal loop. (Tom mucks looper don't work)

    What I'm trying to do is use an iframe and drop a horizontal(led) loop of my filtered images using an included iframe in the main page.
    Last edited by student101; 07-15-2008 at 10:42 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Oh I see. Its a query issue then:
    PHP Code:
    <?php
    if (!isset($_GET['catid']) || empty($_GET['catid']))
    {
        
    // I'm just going to default to 1, you can throw an exception or do whatever
        
    $catID 1;
    }
    else
    {
        
    $catID = (int)$_GET['catID'];
    }
    $sql "SELECT * FROM Photos WHERE yourcatfield=" $catID;
    Might as well change this line too, better to trust you're variables over the get variables:
    PHP Code:
    //start problem area

    echo '<th scope="col"><a href="?catid=' $catID '&img=' $row_rsnav1['image'] . '&navid=' $row_rsnav1['intid'] . '"><img src="uploads/' $row_rsnav1['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n"
    As for duplicates, thats a data integrity thing. You're database might not be normalized allowing duplicate records to exist. You're original query indicates that it always fetches ever record from the Photos regardless of what catid has been chosen.

    Is that what you're asking for?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    No, my code is below the code I found:
    PHP Code:
    <?php if ($totalRows_rsnav1 0) { // Show if recordset not empty ?>
    <?php 
    do { ?>
    <div class="panel" style="width: 100px">

    //////////////////////// Start this part 
    <?php 
    $sql 
    $query_rsnav1;
    $sql1 mysql_query($sql) or die(mysql_error());
    if(
    mysql_num_rows($sql1) > 0)
    {
        
    $i 0;
        echo 
    '<table border="0">'."\n";
        while(
    $result=mysql_fetch_array($sql1))
        {
            if(
    $i &#37; 1 == 1) echo '<tr>'."\n";
    echo '<th scope="col"><a href="?catid=' $_GET['catid'] . '&img=' $row_rsnav1['image'] . '&navid=' $row_rsnav1['intid'] . '"><img src="uploads/' $row_rsnav1['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n";
            
    $i++;
            if(
    $i == 1) echo '</tr>'."\n";
        }
        echo 
    '</table>';
    }
    ?>
    //////////////////////// End this part 

    </div>
    <?php } while ($row_rsnav1 mysql_fetch_assoc($rsnav1)); ?>
    <?php 
    // Show if recordset not empty ?>
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #6
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by Fou-Lu View Post
    Oh I see. Its a query issue then:
    As for duplicates, thats a data integrity thing. You're database might not be normalized allowing duplicate records to exist.
    This page works on the main page, I wanted to use an iframe and use the navigation on it's own page and include it in the main page. (saves refreshing each time a link is clicked)
    I wasn't able to horizontally loop the images - till I found this script that works, except it doesn't.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I'm still confused then, lol.
    Can you describe (or show if you have a online page) what it is doing, and indicate what it is that you want it to be doing? Does it require pagination and how many rows/columns do you require this to be displayed in, etc.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #8
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by Fou-Lu View Post
    I'm still confused then, lol.
    Can you describe (or show if you have a online page) what it is doing, and indicate what it is that you want it to be doing? Does it require pagination and how many rows/columns do you require this to be displayed in, etc.
    FIXED!!
    I kept calling the wrong recordset value, it should have been $result
    PHP Code:
    echo '<th scope="col"><a href="?catid=' $_GET['catid'] . '&img=' $result['image'] . '&navid=' $result['intid'] . '"><img src="uploads/' $result['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n"
    Thank you!
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If you want to use an iframe (which I do not condone but to each their own), you need to separate you're handling from the rest of it, since an iframe requires a page of its own including all the proper headers. If the correct images are not showing up (ie, you are getting all images), it is likely the query is not handling the category selection correctly. After this, you need all other links to target the iframe, otherwise they will default to themselves, which will reload you're page and give you the original iframe that was selected. You can include an iframe in a table, but you must make sure that proper column and row spanning is performed - iframe tables do not effect the page tables.

    Think smaller, if you are for sure using an iframe create a page that accepts the querystring for its lookups and make sure you have everything looking the way you want it to. After that, implement that page into you're primary page by using the iframe. Sticking two working pages together is far easier than trying to break one up into chunks to figure out the problems.

    Edit:
    Glad you got it fixed!
    Sorry, I should have paid more attention when I was rewriting that line to the fact you used $rows_nav1 instead of $result.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #10
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    I only just built the idea today.
    It works fine as one full page(with page refreshes) - I didn't want the navigation to loose it's place, due to page refreshes.

    I have to spend more time - like you say build it up, not break it down.
    Will start again tomorrow.

    No probs, thank you!
    Last edited by student101; 07-15-2008 at 11:45 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •