Help a noob out with some basics

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Whirlpoolz
Forum Newbie
Posts: 3
Joined: Tue Feb 09, 2010 9:40 pm

Help a noob out with some basics

Post by Whirlpoolz »

Hi, I need help displaying information from my database. I'm using a php file and then an html file for the template itself. My php looks something like this:

Code: Select all

$result = $db->query("SELECT * FROM `my_table_here` ORDER BY `field_i_want_to_sort_by` DESC LIMIT 0,10");
{
    $tmp->set_block( 'my_list', $row );
}
I want to display the information in html like this:

Code: Select all

       <!-- start my_list -->
        {my_list.field_1}, {my_list.field_2}<br />
        <!-- stop my_list -->
 
 
So basically, I want to display the different fields of that table. What changes do I need to make to make this work? If you can explain any of the "how"'s or "why"'s of it, that would be cool too. Thanks.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Help a noob out with some basics

Post by klevis miho »

Why is this:
$tmp->set_block( 'my_list', $row );
inside curly brackets?
Whirlpoolz
Forum Newbie
Posts: 3
Joined: Tue Feb 09, 2010 9:40 pm

Re: Help a noob out with some basics

Post by Whirlpoolz »

All of the examples I've seen, they always show that part in the brackets, so I assumed they were supposed to go in there.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Help a noob out with some basics

Post by social_experiment »

Unless $tmp->set_block( 'my_list', $row ) is a function that creates the list somehow, you could use mysql_fetch_array() to display the desired fields :

Code: Select all

<?php $result = $db->query("SELECT * FROM `my_table_here` ORDER BY `field_i_want_to_sort_by` DESC LIMIT 0,10"); 
while ($value = mysql_fetch_array($result)) {
 echo "$value[field1]";
 echo "$value[field2]";
 //etc
}?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Whirlpoolz
Forum Newbie
Posts: 3
Joined: Tue Feb 09, 2010 9:40 pm

Re: Help a noob out with some basics

Post by Whirlpoolz »

I tried that and got the same result. :banghead:

Is the html I posted correct with what I'm trying to do with the php? I know I used that form of displaying the information in the past and got it to work, but I feel very helpless right now.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Help a noob out with some basics

Post by social_experiment »

The html in this example is irrelevant. Could you please post the complete script or attach it as a file, that would be more helpful. What output (if any) do you receive?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply