View Full Version : While loop problem
I have checked and checked so many times and i can't see why this is happening!
$skin = mysql_query( "SELECT id,path,name,description,author FROM skins ORDER BY id ASC LIMIT 10" );
while( $list = mysql_fetch_array( $skin ) )
{
echo "variables and stuff";
}
Now technically speaking it should display what i want in the while loop 10 times in an ascending order. However i have 3 rows in the table and it is currently displaying 2 / 3.
So the latest entry is being missed out for some reason and i can't work out why this is :S
Excellent2
29-09-2008, 06:44 PM
Can't see why it's happening, are you actually echoing the loop variable?
yes i am. Stuff like:
echo $list[ 'name' ]
$list[ 'path' ]
$list[ 'description' ]
$list[ 'author' ];
It works for 2 of the entries but as i said the latest entry doesn't show.
I had this problem when I was making a private messaging system, can't for the life of me remember how I fixed it though.. I suggest you just go over your code, checking all the obvious things, or maybe try a new way of displaying it, sorry I couldn't be of much more help.
Excellent2
29-09-2008, 06:55 PM
Check your PMA for db entries?
Decode
29-09-2008, 07:00 PM
while( $list = mysql_fetch_assoc( $skin ) )
{
echo "variables and stuff";
}
I think
well actually i did try that with:
while( $list = mysql_fetch_array( $skin, MYSQL_ASSOC ) )
{
echo "variables and stuff";
}
But still did the same thing
Excellent2
29-09-2008, 07:11 PM
Check your PMA?
the table for skins is:
id path name description author
1 default Default default skin me
2 dark dark skin Dark skin me
3 light light skin Light skin me
Source
29-09-2008, 07:22 PM
Try this, probably wrong.
$skin = mysql_query( "SELECT * FROM `skins` ORDER BY `id` ASC LIMIT 10" );
while( $data = mysql_fetch_array( $skin ) {
echo $data['description'];
}
You get the idea
Excellent2
29-09-2008, 07:26 PM
Try this:
$skin = mysql_query("SELECT * FROM skins ORDER BY id ASC LIMIT 10");
while ($fetch = mysql_fetch_array($skin)) {
echo "$fetch['name']
$fetch['path']
$fetch['description']
$fetch['author']";
}
Source
29-09-2008, 07:28 PM
*cough* indentation *cough*
Excellent2
29-09-2008, 07:29 PM
Meh, stuff indentation for query's lol.
Source
29-09-2008, 07:30 PM
But.... it looks so pretty :(
Excellent2
29-09-2008, 07:31 PM
But.... it looks so pretty :(LMAO, I like my code ugly :(
Source
29-09-2008, 07:32 PM
lemme guess... girls to?
Back on topic, mine should worketh along with thou excellénts.
Excellent2
29-09-2008, 07:33 PM
lemme guess... girls to?
Back on topic, mine should worketh along with thou excellénts.Yeah, especially after your mother hasn't washed in about a week ;) Mine shal' worketh' without editing because source was to lazy to type it all out..eth!
Decode
29-09-2008, 07:34 PM
Try this:
$skin = mysql_query("SELECT * FROM skins ORDER BY id ASC LIMIT 10");
while ($fetch = mysql_fetch_array($skin)) {
echo "$fetch['name']
$fetch['path']
$fetch['description']
$fetch['author']";
}
That would make "unexpected T_String" I think.
Excellent2
29-09-2008, 07:35 PM
That would make "unexpected T_String" I think.Me no no think so? :O
Hypertext
29-09-2008, 07:40 PM
I don't think you can use LIMIT 10, Use "LIMIT 0, 10"
So, use:
$skin = mysql_query("SELECT * FROM skins ORDER BY id ASC LIMIT 0, 19");
while($fetch = mysql_fetch_array($skin)) {
echo $fetch['name'];
echo $fetch['path'];
echo $fetch['description'];
echo $fetch['author'];
}
You can use limit 10 :P
You only add the 0, 10 if u want to start it from 0, which you do but it isn't necessary.
Well source's wouldnt work because he forgot to close a bracket :D.
But anyways that does the same thing, all thats been changed is the variable name
Hypertext
29-09-2008, 07:43 PM
You can use limit 10 :P
You only add the 0, 10 if u want to start it from 0, which you do but it isn't necessary.
Ah, OK, thanks :)
Try using my code anyway, without echoing it out in double quotes, if not, there is definitely something else wrong, could you perhaps paste the whole file and included files?
If it isn't a large piece, try recoding it?
I often find that helps because you sometimes don't see some errors.
You'd think a community of people would spot it though :rolleyes:
ok this is the page:
<?php
$skin = mysql_query( "SELECT * FROM `skins` ORDER BY `id` ASC LIMIT 10" );
if( $form == "ok" )
{
$skin_choice=htmlspecialchars(stripslashes(mysql_r eal_escape($_POST[ 'skin_choice' ])));
if( $skin_choice == "" )
{
echo "Sorry you didnt pick a skin!";
}
else
{
mysql_query("UPDATE user SET skin='".$skin_choice."' WHERE id='".$usrd[id]."'");
echo "Your settings have been updated!";
}
}
else
{
echo "<form action=\"\" method=\"post\">
<input type=\"hidden\" name=\"form\" value=\"ok\" />
<div id=\"left\">";
while( $fetch = mysql_fetch_array( $skin ) ) {
echo "<div style=\"margin-bottom: 20px;\">
<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
<tr>
<td><img src=\"".$url."images/skins/".$fetch[ 'path' ]."/skin.png\" width=\"200\" height=\"100\" alt=\"\" border=\"0\" /></td>
<td width=\"50\"></td>
<td valign=\"top\"><h2> ".$fetch[ 'name' ]." </h2> ".$fetch[ 'description' ]." <br /> <span style=\"font: 10px arial; color: orange;\"> Skin created by <em>".$fetch[ 'author' ]."</em></td>
<td valign=\"top\"> <span style=\"font: 11px arial; color: #333;\"> Use this skin? </span> <input type=\"radio\" name=\"skin_choice\" value=\"".$fetch[ 'id' ]."\" /> </td>
</tr>
</table>
</div>";
}
echo "<div class=\"save\"> <input type=\"submit\" value=\"Save this skin\" class=\"save\" /> </div>
</form>";
}
?>
Excellent2
29-09-2008, 07:56 PM
If the code all of us have done for you doesn't work check your PMA, if nothing is in there it's the script you're using to submit the information.
The script im using to submit the information? what do you mean by that?
Excellent2
29-09-2008, 08:07 PM
The script im using to submit the information? what do you mean by that?Skins, sorry.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.