Random Posted April 6, 2003 Share Posted April 6, 2003 How do I print a row from mysql? This is the script I was trying ( newbie at this ): [php:1:71284b16c1]<?php print \"<BR><BR><BR><BR>\"; $conn = mysql_connect(\"localhost\", \"random\", \"random\") or die (\"Couldn\'t Connect...\"); print \"Connected!\"; $db = \"random\"; mysql_select_db($db, $conn) or die (\"Couldn\'t connect\"); $result = mysql_query( \"SELECT * FROM user_info \"); $fetch = mysql_fetch_row( $result ); print \" $fetch \"; mysql_close( $conn ); ?> [/php:1:71284b16c1] It prints out: \"Connected! Array\"; where Connected is from the successful connect, and I guess $result is printing Array. Any help is appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/ Share on other sites More sharing options...
LiamG Posted April 6, 2003 Share Posted April 6, 2003 First, it says \"Print\" because of the line [php:1:6c27594e10]print \"Connected!\";[/php:1:6c27594e10]If you don\'t want it to say that, delete the line! YAY! One down. Next, it says array for a reason unknown to me, however if you put a @ before the comment mysql_fetch_array you might find it will supress that. I don\'t REALLY know though. HTH, LiamG. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-971 Share on other sites More sharing options...
Random Posted April 6, 2003 Author Share Posted April 6, 2003 I was just pointing out why it says connected that wasnt a problem hehe Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-972 Share on other sites More sharing options...
LiamG Posted April 6, 2003 Share Posted April 6, 2003 What about the array problem? LiamG. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-973 Share on other sites More sharing options...
Random Posted April 6, 2003 Author Share Posted April 6, 2003 [php:1:10dbd8e8ef]<?php $fetch = @mysql_fetch_row( $result ); ?>[/php:1:10dbd8e8ef] so it looks like that? if so that didn\'t work. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-974 Share on other sites More sharing options...
LiamG Posted April 6, 2003 Share Posted April 6, 2003 Try putting it infront of the mysql_query. LiamG. ps - Shiva or someone might be able to more accurately answer this question later. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-975 Share on other sites More sharing options...
Random Posted April 6, 2003 Author Share Posted April 6, 2003 still didn\'t work. yeah I will wait for shiva to get on. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-976 Share on other sites More sharing options...
DocSeuss Posted April 6, 2003 Share Posted April 6, 2003 $fetch IS an array that is why the work array is printing out. you would have to print each element sepeartly print $row[0]. \", \". $row[1]. \", \" ect. or you can use $row[\'fieldname\'] for each column in the table. the way you have the code set up is only going to output the first row of the table if you want to print them all. while($fetch = mysql_fetch_row($result)) { print $row[0] . \", \" $row[1], ect.. } I\'ve just used a comma to seperate each one but that all depends on how you want your output to be displayed on the screen. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-978 Share on other sites More sharing options...
LiamG Posted April 6, 2003 Share Posted April 6, 2003 There you go, Doc answered it. Thanks Doc! LiamG. Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-979 Share on other sites More sharing options...
Random Posted April 16, 2003 Author Share Posted April 16, 2003 Thanks Doc! I just checked it, and it worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-1178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.