Jump to content

Simple php sql retrieve help


gibigbig

Recommended Posts

ok i need some help retrieving some data from my database.

this is my database structure:

 

id
name
author
article_author
article_date
genre
debut
last release
tags
forum_id
display
description
rating_given
rating_total

I would like to call on these table fields within my template using this format

echo 'this is some random text '. $author .' and some more here ';

 

can some one please help me

Link to comment
https://forums.phpfreaks.com/topic/169728-simple-php-sql-retrieve-help/
Share on other sites

You can always assign the mysql results into php variables/arrays and pass the arrays/variables on to the template or further use some elsewhere.

 

<?php
$sql = "SELECT * FROM some_table WHERE author = 'some_author'";
$data = array();
$i = 0;
$result = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_array($result))
{
    $data[$i]['author'] = $row['author'];
    $data[$i]['name'] = $row['name'];
    $data[$i]['article_date'] = $row['article_date'];
    // etc..
    $i++;
}

 

Then use the data array which holds the results as you wish and were you wish.

 

And if you have problems figuring out the structure while using the array you can do the below and see the structure in more readable format.

<?php
echo '<pre>';
print_r($data);
echo '</pre>';

Archived

This topic is now archived and is closed to further replies.

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