Forum Moderators: coopster

Message Too Old, No Replies

? query repeated till end of execution time?

         

Twisted Mind

3:20 pm on Feb 11, 2006 (gmt 0)

10+ Year Member



Hi i have been off php for a while.
I installed XAMPP (cuz im lazy) now i created a table with some content (this is not inportant what it does)

i have this script

<?
//including teh dbconnection script
include"conn.php";

while($links = mysql_fetch_row( mysql_query('select * from content))) {echo $links[id];};

?>

Its So small its almost inpossible to detect an error in it.

Anyways what it does now is puttying as many times the id after eachother but i dont know why it does this. Anyone experianced this before?

Thanks for you help :D.

henry0

11:05 pm on Feb 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A couple of things you can do

Adding a limitative clause like:
for ex:

('select * from content where whatever=’$wharever’)))

Or
('select * from content ORDER BY user_id DESC LIMIT 1)))

or combo

('select * from content where whatever=’$wharever’ ORDER BY user_id DESC LIMIT 1)))

While looking around I found a thread [webmasterworld.com] that can give you
some help about looping

Twisted Mind

10:47 am on Feb 12, 2006 (gmt 0)

10+ Year Member



Ill look in to it thanks for teh reply.

Twisted Mind

10:48 am on Feb 12, 2006 (gmt 0)

10+ Year Member



oh this is al for multiple tables i only require to get all rows from table content... it has only 1 record but it keeps on repeating him...

anyways teh query is okay becouse when i use it in sqlyog it will return only 1 row.

DrDoc

6:28 pm on Feb 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Take out the while.

Just do:

$links = mysql_fetch_row(mysql_query('select * from content'));
echo $links[id];

Twisted Mind

7:54 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



k

Twisted Mind

10:03 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



Strange why did u post that? it does nothing... Just nothing no errors or whatsoever...

Is this maybe a problem with the php version i am using? 5.2 something i believe...

WHILE ($row = mysql_fetch_row(mysql_query('select * from content')))

ITS JUST THIS LINE WHAT TEH **** IS WRONG I CANT FIND IT RAAGHH evertime i get this max execution time... this just sux

DrDoc

10:23 pm on Feb 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, then perhaps you need to better explain what exactly you are trying to accomplish.

Give a brief overview of what's in the table, and what you expect the query to do, and what the desired output should be ...

Perhaps you also need to read up on what the error means: [php.net...]

Twisted Mind

7:02 am on Feb 13, 2006 (gmt 0)

10+ Year Member



I made loads of query's the only thing this query Should be doing is displaying the primary keys of the table content.

The table content:

id title link content
1 home home this is the test home page

Im just askin mysql to loop the id's.

Here is the code (not big at all):

<?
//including teh dbconnection script
include"conn.php";

WHILE ($row = mysql_fetch_row(mysql_query('select * from content')))

?>

DrDoc

7:30 am on Feb 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SELECT DISTINCT id FROM content

?

Or, no?

Twisted Mind

8:55 am on Feb 13, 2006 (gmt 0)

10+ Year Member



does nothing... im not at home at the moment but my query should work alrite in the way i posted it wouldnd it?

DrDoc

4:43 pm on Feb 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I always get the result set first, then loop through it.
Perhaps PHP re-runs the query the other way?
If so, this should work.

<?
//including teh dbconnection script
include("conn.php");
$result = mysql_query('select * from content');
while($links = mysql_fetch_row($result)) { echo $links[id]; }
?>