PDA

View Full Version : Trouble displaying my mysql data


Punk Rock Geek
11-05-2006, 03:54 AM
$query2 = $DB->query( "SELECT post FROM mkp_blog_post WHERE id_blog='2485' ORDER BY 'id'");

I simply want the results of this query to show up on my page. I know the query works, because I tried it in PHP Myadmin, and it gave two results. However, when I go the page, it doesn't work.

Yes, I have more lines of code after that, but nothing I have tried has worked. Does anyone know what I would need to write afterwards as so this would appear on my page? Thanks!

CFMaBiSmAd
11-05-2006, 04:06 AM
Without seeing your db class function documentation or code definition, the following is only a guess - If we assume that this returns a result set and assigns it to $query2, this should do something -
while ($row = mysql_fetch_assoc($query2)) {
echo $row["post"];
}

Punk Rock Geek
11-05-2006, 04:26 AM
That did not work CFMaBiSmAd. I assume the "post" was supposed to be "mkp_blog_post"? I made that change. Anyways, this is what I currently have, and it doesn't work either:

while( $row = $DB->fetch_row($query2) ) {
$contacts2 = $row['mkp_blog_post'];

$output = "
$contacts2
";
print $output;
}

CFMaBiSmAd
11-05-2006, 04:45 AM
Your query statement is selecting the column post - "SELECT post

mkp_blog_post is the table name.

Punk Rock Geek
11-05-2006, 04:51 AM
Wow. I am such an idiot. I can't believe I made that mistake. For some reason I was completely 100% convinced that the table name was mkp_blog_post. Thanks for seeing that error!

CFMaBiSmAd
11-05-2006, 04:58 AM
For some reason I was completely 100% convinced that the table name was mkp_blog_post.According to the query string, the table name is mkp_blog_post.

In a Forum, we only "see" what you describe, post, or provide a link to. Everything else is just a guess or relies on mind reading over the Internet, which only works when the moon is in the right phase... :D

Punk Rock Geek
11-05-2006, 05:21 AM
Sorry, not table. I meant column.

Okay, so this is all of my data now. Just for clarification, my purpose is to get everyone on my friends list to have their blog entries displayed on a single page.

This first query is one you haven't seen yet.


It selects all of the contacts on user 1's (my) friend list. It sets them to a single variable, "$contacts".
$query = $DB->query( "SELECT contact_id FROM ibf_contacts WHERE member_id='1'");


while ($row = mysql_fetch_assoc($query)) {
$contacts = $row['contact_id'];

}





$query2 = $DB->query( "SELECT post FROM mkp_blog_post WHERE id_blog='$contacts' ORDER BY 'id'");

while ($row = mysql_fetch_assoc($query2)) {
echo $row["post"];
}


The id_blog='2485' in the 2nd query has been changed to id_blog='$contacts' which means that now it looks for every blog id that matches the id of the people on my friends list. However, I think it is only doing one at a time, because I am still only getting blog entries from a single user to display. Help?

guelphdad
11-05-2006, 02:41 PM
get your query to work properly without trying to display it in PHP code. then when you know your query is working properly, any problem after that is with your PHP code either used to interact with your sql query or to display the results of the query.

Does your query itself (outside of php code) actually produce the proper results you are looking for? if it does then I can move this thread to the PHP area where you will get help with your php code. iF your query (outside of php code) DOES NOT give you your intended results then please show only your query along with some sample rows of data from your table(s) and your expected output.

At that point we can help you with your query, get it working and then move the thread over to PHP forum.

Punk Rock Geek
11-05-2006, 07:21 PM
Okay, I started a new thread there because I have fixed this problem, but have a new, less complicated one. Check it out here:

http://www.codingforums.com/showthread.php?p=502783#post502783

guelphdad
11-06-2006, 01:21 AM
Punk Rock Geek. Two points. One, when you solve a problem, post that in the thread, then those who follow into the thread with a similar problem may have a solution that works for them or gets them in the right direction.

Secondly, if your two types of problems are similar enough and work with the same set of data, please request to move a thread rather than start another. That will prevent answers showing up in both theads where folks may not know some of the solution has already been posted in the other thread.