Jump to content

kisazeky

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kisazeky's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a loop code that grabs data from the database and lists it on a webpage. $article_title = "Shop"; $article_content = "Shop description goes here.<table<tr>"; $query = "SELECT * FROM adoptables WHERE kind = 'shop'"; $result = mysql_query($query); $num = mysql_numrows($result); //Loop out code $i=0; while ($i < $num) { $aID=@mysql_result($result,$i,"uid"); $name=@mysql_result($result,$i,"name"); $imageurl=@mysql_result($result,$i,"imageurl"); $cost=@mysql_result($result,$i,"description"); //Content output $article_content=$article_content."<td>".$name."<p><img src='".$imageurl."'/><p>".$cost." <p><a href='buy.php?aID=".$aID."'>Buy ".$name."</a></td>"; $i++; } $article_content=$article_content."</tr><tr>"; I want to arrange the data in table columns, with 5 items per row. How can I accomplish this?
  2. Thanks, teen. I was modeling this off of someone else's code, so I believed you had to loop queries all the time. From now on I'll use what you showed me unless I really do need to loop data.
  3. I did this: $query = "SELECT * FROM `users` WHERE `username` = '".$luser."'"; $result = mysql_query($query); $num = mysql_numrows($result); $i=0; while ($i < 1) { $money =@mysql_result($result,$i,"money"); $i++; } $query = "SELECT * FROM adoptables WHERE uid = '$aID'"; $result = @mysql_query($query); $num = @mysql_numrows($result); //Loop out code $i=0; while ($i < 1) { $aID=@mysql_result($result,$i,"uid"); $name=@mysql_result($result,$i,"name"); $imageurl=@mysql_result($result,$i,"imageurl"); $cost=@mysql_result($result,$i,"description"); $i++; } Does this stop the infinite loop?
  4. I had an account suspended on a paid, shared web host recently. They said it was because one of my php pages was taking up more than 10% CPU time. What's shocking is that looking at the reports, it was nearly 10 times that! Now I have a hunch as to why this happened. Here's a bit of code from buy.php: $query = "SELECT * FROM `users` WHERE `username` = '".$luser."'"; $result = mysql_query($query); $num = mysql_numrows($result); $i=0; while ($i < 1) { $money =@mysql_result($result,$i,"money"); $query = "SELECT * FROM adoptables WHERE uid = '$aID'"; $result = @mysql_query($query); $num = @mysql_numrows($result); //Loop out code $i=0; while ($i < 1) { $aID=@mysql_result($result,$i,"uid"); $name=@mysql_result($result,$i,"name"); $imageurl=@mysql_result($result,$i,"imageurl"); $cost=@mysql_result($result,$i,"description"); if($money < $cost){ $article_title = "Oops"; $article_content = "You don't have enough bits to afford $name. <a href='shop.php'>Go back</a>."; } else { I noticed that when the conditions met that If statement, the page would time out. So I added $i++; } to close the output of both those queries, and now it loads fine. So my question to you php freaks is: Is it likely that not closing the output properly caused this much load on the CPU? I don't get much traffic to my site.
  5. Hi there, I've recently implemented a profile system on my site that, when given a valid username, will get his/her information from the user table and display it. But, how can I make it return a page "User not found!" if, well, the user can't be found. Thanks. My query looks like this: $query = "SELECT * FROM owned_adoptables WHERE owner = '$owner' ORDER BY uid DESC LIMIT 0,5 "; $result = mysql_query($query); $num = mysql_numrows($result); //Loop out code $i=0; while ($i < $num) { $id=@mysql_result($result,$i,"uid"); $name=@mysql_result($result,$i,"name"); $imageurl=@mysql_result($result,$i,"imageurl");
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.