Re: What am i doing wrong? SQL Query in PHP

From: Date: Sun, 09 Mar 2003 14:55:31 +0000
Subject: Re: What am i doing wrong? SQL Query in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-138859@lists.php.net to get a copy of this message
On Sun, 9 Mar 2003 04:37:47 -0800 (PST), Rahul.Brenda <rahul_brenda@yahoo.com> wrote:
I want to display the first 3 words of my record in the my table and following is the code i'm using. When i use the SQL Query in mySQL.. it works great.. but when i try to implement it in my php page.. i'm not getting anything.. no error, no display, no result.. just blank.. why? <?php $db = mysql_connect("localhost","user","pass"); mysql_select_db("mydb",$db); $result = mysql_query("SELECT substring_index(title, ' ', 3) from news order by ID desc limit 4",$db); if ($myrow = mysql_fetch_array($result)) { do { echo(" $myrow[title] "); } while ($myrow = mysql_fetch_array($result)); } ?> Rahul S. Johari
Why not do it like this? // fetch row is faster than fetch_assoc, which is faster than fetch_array // fetch_result might even be a better choice here, though, with only one item... if (!mysql_num_rows($result)) { print 'no results'; } else { while (list($title) = mysql_fetch_row($result)) { print $title; // don't quote variables if you only want to print them by themselves } } -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

« previous php.general (#138859) next »