Results 1 to 3 of 3

Thread: php problem...

  1. #1
    Member
    Join Date
    Jul 2003
    Posts
    139
    Thanks
    0
    Thanked
    0 times in 0 posts

    php problem...

    i have a problem, i am tryong to clean up my code, but have run into problems...

    before i had :
    PHP Code:
    $result mysql_query("                SELECT template
                                        FROM template
                                        WHERE template_id = '3'"
    )

    or die (
    "Couldn't Execute Query");

    $row mysql_fetch_array($result);

    $templateno $row[template]; 
    i had about 20 of them ^ for each template i am using, but i want to load them all with one loop and query, rather then with 20 or so. the db is layed out in 3 columns; template_id, template_name, and template(which is the one where the template info is stored). i want to load each teplate cell and assighn the contents a varible name, as in the above code, but i dont want to do it with 20 querys if i can help it

  2. #2
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,185
    Thanks
    739
    Thanked
    1,614 times in 1,050 posts
    Use a while statment with fetch_object. Somthing like :

    PHP Code:

    <?
    // do querys here, query = $result

    // if records present
    if (mysql_num_rows($result) > 0)
    {
        
    // iterate through resultset
        // print whatever is needed.

        
    while($row mysql_fetch_object($result))
        {
        
    ?>

    Do whatever you want here, echo the result/s you want, with any HTML formating

    <?
    // close loops
    }}
    ?>
    This will complete the loop, move onto the next result in the array, complete the loop and so on..

    edit - missed out the end of the second loop - updated now.
    Last edited by Agent; 02-10-2003 at 11:21 PM.
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  3. #3
    ICY
    ICY is offline
    Registered+
    Join Date
    Oct 2003
    Posts
    15
    Thanks
    0
    Thanked
    0 times in 0 posts
    PHP Code:
    <?php

    $result 
    mysql_query("SELECT template FROM template ORDER BY 'template_id' asc")

    or die (
    "Couldn't Execute Query");

    for(
    $i 0$i $result$i++)
    {
        
    $row mysql_fetch_array($result);
        
        
    $row['template'] = $template[$i];
    }

    while(
    $i >1)
    {
        echo 
    $template[$i] .'<br/>';
    }

    ?>
    i think this will work, havent tested it myself though, the end bit *should* output the template name in a list, if it works correctly that is...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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