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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with printing out results from mysql

    Code:
    $Link = mysql_connect ($Host, $User, $Password);
    $Query = "SELECT * from $TableName";
    $Result = mysql_db_query ($DBName, $Query, $Link);
    
    if ($Result) {
    	print ("The query was successfully executed!<BR>\n");
    	while ($Row = mysql_fetch_array($Result)) {
    		print ("$Row[Products]");
    	}
    } else {
    	print ("The query could not be executed!<BR>\n");
    }
    mysql_close ($Link);
    I'm getting The query was successfully executed! printed out on the page so I'm assuming it found the database and table correctly? What I'm trying to do is grab every Record set's text that is in the products column. I think the syntax is correct because I'm not recieving any syntax errors. The problem I'm having is with printing out the results it found. It's just not printing anything out. Can anyone help me?

    Edit:
    I put an echo under print ("$Row[Products]"); to print out Row and it printed out 13 times which is how many rows I have in that table. So now I def know my query is right. Now I'm just stuck on how to print out the text that is in the Product column.

    -Thanks,
    Rich
    Last edited by DiarYofaMadmaN; 04-30-2004 at 03:26 AM.

  • #2
    New Coder
    Join Date
    Mar 2004
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind I figured it out. where it says: print ("$Row[Products]"); I typed Products instead of Product. Product is the correct column name.

    -peace

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,075
    Thanks
    11
    Thanked 98 Times in 96 Posts
    glad you got it sorted , quick note though ...

    technically $Row[Product] is incorrect,it should be $Row['Product'] as $Row[Product] & $Row['Product'] could mean 2 totally different things if `Product` was a constant.

    also (and this is just coding preference & no more than that ), most peeps would use echo() over print();

    PHP Code:
    <?php
    echo $Row['Product'];
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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