Jump to content

I need help pulling an ID from your database.


therocker

Recommended Posts

So I'm having issue with trying to pull the ID from my database out correctly.

This is the ideal way I want the ID to be pulled.

 

http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc6/226659_219275201434540_100000561868489_827151_3402533_n.jpg

 

But then it always pulls the ID like this and stacks the number ID ontop of each other and I want it to have separate DIVS.

 

http://photos-e.ak.fbcdn.net/hphotos-ak-snc6/226659_219275204767873_100000561868489_827152_3422285_n.jpg

 

This is the code that I'm using. Tell me what I'm doing wrong.

 

<?
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

echo "<div class=\"body_resize\"><div class=\"left\"><br /><span class='date'>$timedate</span><br /><br />";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("<h2>#%s</h2>", $row["id"], $row["name"]);
}

mysql_free_result($result);

echo "<br /><div class=\"comment_gravatar left\"><img alt=\"\" src=\"http://photos-b.ak.fbcdn.net/hphotos-ak-snc6/229186_219276548101072_100000561868489_827154_8135363_n.jpg\" height=\"32\" width=\"32\" /></div><p>Posted By $name<br><br /><p>$message</p><br></div><div class=\"clr\"></div></div>";
if ($ip==$userip && $delcom==1) {
?>

Link to comment
Share on other sites

You are printing the IDs in the a while loop which loops over all the results of the table, so I would expect the stacked IDs to be the output.

 

If you intend to print only 1 ID for 1 post on the page, narrow down your mysql query to select only the relevant ID.

 

If you intend to print 1 ID for each post on the page, include the post-printing code within the while loop as well, to ensure that on each iteration of the loop, the ID is printed once together with the post.

Link to comment
Share on other sites

You are printing the IDs in the a while loop which loops over all the results of the table, so I would expect the stacked IDs to be the output.

 

If you intend to print only 1 ID for 1 post on the page, narrow down your mysql query to select only the relevant ID.

 

If you intend to print 1 ID for each post on the page, include the post-printing code within the while loop as well, to ensure that on each iteration of the loop, the ID is printed once together with the post.

 

And how is this possible?? If I move the ID away from the while loop, the ID will not get displayed, if I leave it in there, it will stack up and it will show errors, I need help trying to move the ID to a different part of the code that it will be able to read and display at the same time with out showing just #%s in there because I tried to move #%s outside of the while loop and I tried to move the second DIV to another part of the code and I get the same exact results, it seems that I'm not getting the answer I'm wanting for. And people may have not get what I wanted the results to be.

Link to comment
Share on other sites

This is the desired results, people have been telling me all these things, but they don't end up to be like this. This is how I want it to be, but no one seems to be giving me the right answer I need. This is just photoshopped so don't expect that I got it right. No one seems to understand what I'm trying to ask and so I just photoshopped this part so people can get a better understanding instead of giving me wrong results.

 

 

249259_222917351070325_100000561868489_853909_4941219_n.jpg

Link to comment
Share on other sites

I, for one, have understood what you want from the start, and have nicely given you the solution:

 

If you intend to print 1 ID for each post on the page, include the post-printing code within the while loop as well, to ensure that on each iteration of the loop, the ID is printed once together with the post.

 

If you do not understand what I posted, simply ask nicely and I will elaborate. I don't know if you have asked for help outside of this thread, but it's no use venting your frustrations here. If you are not getting the help you want (for free) in this forums, suck it up. We don't owe you answers.

 

Having cleared that up, I was suggesting placing the "post-printing" portion of your code in the while loop as such:

 

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("<h2>#%s</h2>", $row["id"], $row["name"]);
    echo "<br /><div class=\"comment_gravatar left\"><img alt=\"\" src=\"http://photos-b.ak.fbcdn.net/hphotos-ak-snc6/229186_219276548101072_100000561868489_827154_8135363_n.jpg\" height=\"32\" width=\"32\" /></div><p>Posted By $name<br><br /><p>$message</p><br></div><div class=\"clr\"></div></div>";

}

 

I don't know where/how your $name and $message fields are populated, but you will have to make sure that the appropriate values are assigned to them within the while loop for each post, so that the message is different below each ID.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.