gibigbig Posted August 11, 2009 Share Posted August 11, 2009 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 Quote Link to comment Share on other sites More sharing options...
priti Posted August 11, 2009 Share Posted August 11, 2009 $recordSet=mysql_query(select * from tablename); while($row=mysql_fetch_assoc($recordSet)) { echo $author =$row['author']; } Quote Link to comment Share on other sites More sharing options...
gibigbig Posted August 11, 2009 Author Share Posted August 11, 2009 yes i already know about that but wouldnt that mean i have to fit my entire template's code inside the "while" function? edit: btw its a joomla component so isn't there an already premade function for this? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 11, 2009 Share Posted August 11, 2009 It depends on how the page is formatted, you could also do this: $row = mysql_fetch_array($sql); echo $author =$row['author']; But this will only work if you only get one result from the database. Quote Link to comment Share on other sites More sharing options...
gibigbig Posted August 11, 2009 Author Share Posted August 11, 2009 none of the above suggestions seems to work Quote Link to comment Share on other sites More sharing options...
priti Posted August 13, 2009 Share Posted August 13, 2009 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 !!! :-) Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 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>'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.