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
Share on other sites

As you said

 

"btw its a joomla component so isn't there an already premade function for this?"

 

then you need to look in to the code of joomla CMS or you can post the same query in joomla forum you will get prompt help !!! :-)

 

 

Link to comment
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>';

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.