Jump to content

Problem fetching database results


luke101

Recommended Posts

Hello, I am having a problem fetching the data from the database. When i use

$row[0];

$row[1];

 

The code below does not works. How would I make the code below work?

 

$resourcearray = "SELECT mainlist.title, resourcelist.title, resourcelist.description, resourcelist.Resource_Date FROM mainlist
			inner join resourcelist on mainlist.id = resourcelist.MainList_Key
			WHERE resourcelist.author=$userid";

$result = selectstatement($resourcearray);
echo "Resources: <br />";
while($row = mysql_fetch_array($result))
{
?>
<strong><?php echo $row['mainlist.title']; ?></strong><br />
<?php echo $row['resourcelist.title']; ?><br />
<?php echo $row['resourcelist.description']; ?><br />
<br /><br />
<?php
}

Link to comment
https://forums.phpfreaks.com/topic/68253-problem-fetching-database-results/
Share on other sites

Im sorry, you're really going to have to help us help you here.

 

The code below works. How would I make the code below work?

 

Im guessing that was a typo, and 'the code below' doesn't work. However, what do you mean by doesn't work? What happens? What's supposed to happen? Do you get an error? What 'problem' are you having?

 

Im not being rude, its just impossible to help without knowing what we're trying to help with!

when i use:

$row[0];

$row[1];

Then the code works

 

 

When I use :

$row['mainlist.title'];

$row['resourcelist.title'];

$row['resourcelist.description'];

Then the code does not work

 

I would like to use the $row['mainlist.title']; sytax to get information from the database. Can i do this?

Ah ok, well you dont need the table name in the key of the array. Since you have more than one field with the same name(which are across differant tables) you'll need to use AS to rename the results. For example:

 

$resourcearray = "SELECT mainlist.title AS maintitle..."

 

You'd then use that by using $row['maintitle'];

 

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.