shoutdots Posted April 21, 2007 Share Posted April 21, 2007 Why this loop never stop ! <body> <table width="480" border="0" align="center" cellpadding="3" cellspacing="3"> <tr> <td width="32" bgcolor="#D5EAB9"><div align="center" class="style3">ID</div></td> <td width="323" bgcolor="#D5EAB9"><div align="center" class="style3">POLL NAME</div></td> <td width="42" bgcolor="#D5EAB9"><div align="center" class="style3">Edit</div></td> <td width="44" bgcolor="#D5EAB9"><div align="center" class="style3">Remove</div></td> </tr> <tr> <?php include ("mysql_connect.php"); $query="SELECT (id,poll_name) FROM poll_setting WHERE (id=1)"; while ($var="mysql_fetch_array($query)") { ;?> <td height="25" bgcolor="#F4F4F4"><div align="center" class="style5"><? echo ($fetch['id']); ?></div></td> <td bgcolor="#F4F4F4"><div align="center" class="style5"><? echo ($fetch['poll_name']); ?></div></td> <td bgcolor="#F4F4F4"><div align="center"><span class="style4"><span class="style5"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style7"><span class="style5"><span class="style8"><span class="style5"></span></span></span></span></span></span></span></span></span></span></span></div></td> <td bgcolor="#F4F4F4"><div align="center"><span class="style4"><span class="style5"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style7"><span class="style5"><span class="style8"><span class="style5"></span></span></span></span></span></span></span></span></span></span></span></div></td> </tr> <? }; ?> </table> can someone help ? Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/ Share on other sites More sharing options...
centenial Posted April 21, 2007 Share Posted April 21, 2007 Looks like you have some weird characters before your "include" and "query" lines. Try removing those. Edit: Try changing it to this: <body> <table width="480" border="0" align="center" cellpadding="3" cellspacing="3"> <tr> <td width="32" bgcolor="#D5EAB9"><div align="center" class="style3">ID</div></td> <td width="323" bgcolor="#D5EAB9"><div align="center" class="style3">POLL NAME</div></td> <td width="42" bgcolor="#D5EAB9"><div align="center" class="style3">Edit</div></td> <td width="44" bgcolor="#D5EAB9"><div align="center" class="style3">Remove</div></td> </tr> <tr> <?php include ("mysql_connect.php"); $query="SELECT (id,poll_name) FROM poll_setting WHERE (id=1)"; $result = mysql_query($query); while ($var = mysql_fetch_array($result)) { ;?> <td height="25" bgcolor="#F4F4F4"><div align="center" class="style5"><? echo ($fetch['id']); ?></div></td> <td bgcolor="#F4F4F4"><div align="center" class="style5"><? echo ($fetch['poll_name']); ?></div></td> <td bgcolor="#F4F4F4"><div align="center"><span class="style4"><span class="style5"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style7"><span class="style5"><span class="style8"><span class="style5"></span></span></span></span></span></span></span></span></span></span></span></div></td> <td bgcolor="#F4F4F4"><div align="center"><span class="style4"><span class="style5"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style6"><span class="style7"><span class="style5"><span class="style8"><span class="style5"></span></span></span></span></span></span></span></span></span></span></span></div></td> </tr> <? }; ?> </table> Note the mysql_query() line. You'll also want to change the variables inside the while loop from $fetch to $var. Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-234886 Share on other sites More sharing options...
shoutdots Posted April 21, 2007 Author Share Posted April 21, 2007 where is the weird chars ?, I've changed to the $var but it keeps looping with "m" displayed in the required rows. !! Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-234887 Share on other sites More sharing options...
ataria Posted April 21, 2007 Share Posted April 21, 2007 Nevermind. Didn't see it. -relooking over. Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-234891 Share on other sites More sharing options...
Barand Posted April 21, 2007 Share Posted April 21, 2007 while ($var="mysql_fetch_array($query)") { You are assigning the string "mysql_fetch_array($query)" to $var instead the the result of the function call. Remove the quotes. And as stated, you should be echoing $var['poll_name'] and not $fetch['poll_name'] etc Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-234937 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 while ($var="mysql_fetch_array($query)") { You are assigning the string "mysql_fetch_array($query)" to $var instead the the result of the function call. Remove the quotes. sorry, i didn't get here, what should i do ?! Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235123 Share on other sites More sharing options...
Lumio Posted April 22, 2007 Share Posted April 22, 2007 When you say $var="mysql_fetch_array($query)" and echo $var you get that: mysql_fetch_array() And thats true... forever You want to give $var the value of mysql_fetch_array not the value "mysql_fetch..." So remove the quotes: while ($var=mysql_fetch_array($query)) { //... Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235125 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 I've put it like this: $query="select * from poll_setting where (id=1)"; while ($var=mysql_fetch_array($query)) { ; ?> it gives me this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\vs\admin\remove_edit.php on line 25 i am sorry i am totally noob lol Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235130 Share on other sites More sharing options...
Barand Posted April 22, 2007 Share Posted April 22, 2007 You define the query but never execute it try <?php include ("mysql_connect.php"); $query="SELECT (id,poll_name) FROM poll_setting WHERE (id=1)"; $result = mysql_query($query) or die (mysql_error()."<p>$query</p>"); // execute the query while ($var = mysql_fetch_array($result)) { // other code here } ?> Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235131 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 ok I've put what you give me, but when i try to run it it gives me Operand should contain 1 column(s) SELECT (id,poll_name) FROM poll_setting WHERE (id=1) Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235134 Share on other sites More sharing options...
Barand Posted April 22, 2007 Share Posted April 22, 2007 Remove parentheses in SELECT clause Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235136 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 where is these parentheses? ??? sorry my English is not very good, iam trying to learn :'( Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235138 Share on other sites More sharing options...
Barand Posted April 22, 2007 Share Posted April 22, 2007 Remove "(" and ")". Those in WHERE clause are OK SELECT id, poll_name FROM poll_setting WHERE (id=1) Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235139 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 now its looping but I've the same problem that it never stop and gives me "m" letter in the fetching field "id" , "poll name". thats is the final script : <body> <table width="430" height="54" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="43" height="27" bgcolor="#333333"><div align="center" class="style1">ID</div></td> <td width="171" bgcolor="#333333"><div align="center" class="style1">NAME</div></td> <td width="107" bgcolor="#333333"><div align="center" class="style1">EDIT</div></td> <td width="109" bgcolor="#333333"><div align="center" class="style1">REMOVE</div></td> </tr> <?php include ("mysql_connect.php"); $query="SELECT id, poll_name FROM poll_setting WHERE id=1"; $result =mysql_query($query) or die (mysql_error()."<p>$query</p>"); // execute the query while ($var="mysql_fetch_array($result)") { ; ?> <tr> <td><? echo $var['id']; ?></td> <td><? echo $var['poll_name']; ?></td> <td> </td> <td> </td> </tr> <? }; ?> </table> </body> Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235144 Share on other sites More sharing options...
Barand Posted April 22, 2007 Share Posted April 22, 2007 The quotes have crept back into the code while ($var="mysql_fetch_array($result)") { should be while ($var = mysql_fetch_array($result)) { Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235145 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 FETCHED, FETCHED ! LOL i've seen the quota but you've put in the last code you gave it to me, so i didn't remove them. but it gives me only the value where the id=1 Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235148 Share on other sites More sharing options...
paul2463 Posted April 22, 2007 Share Posted April 22, 2007 but it gives me only the value where the id=1 its doing exactly what this query is telling to do <?php $query="SELECT id,poll_name FROM poll_setting WHERE (id=1)"; ?> select the id and poll_name from the table poll_setting but ONLY the one who's ID is equal to 1 Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235149 Share on other sites More sharing options...
shoutdots Posted April 22, 2007 Author Share Posted April 22, 2007 Ok Done now , I've removed " WHERE ID=1 " to fetch all data Million Thanks for all who helped me specially Barand P.S: I will make code headache here for all of you Link to comment https://forums.phpfreaks.com/topic/48063-solved-why-this-loop-never-stop/#findComment-235151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.