Jump to content

[SOLVED] Array help


spires

Recommended Posts

Hi

 

I'm rubbish with arrays, can anyone help?

 

i'm trying put information from my database into an array.

then pull them out one by one.

 

I'm trying to only get the 1st and the 5th entry.

 

example:

$array['0']

$array['5']

 

	$sql3 = "SELECT * FROM pages WHERE page_cat='bread_crumb'";
	$select_query3 = mysql_query($sql3) or die ('error1');
	$count3 = mysql_num_rows($select_query3);
	$row3 = mysql_fetch_array($select_query3);
	$page_name = $row3['page_name'];
	$page_status = $row3['page_status'];
	$page_url = $row3['page_url'];
	$page_cat = $row3['page_cat'];
	$page_order = $row3['page_order'];

$array = array($page_name);
echo $array['0'];
echo $array['5'];

 

 

Thanks for any help

 

 

 

Link to comment
Share on other sites

I dont quite understand what you mean,

how many rows are likely to be returned from each of the queries?

if there are more than one then you probably will need a while loop to fill the array

 

if it is only one then the array $row3 can be used

 

which information are you after?

Link to comment
Share on other sites

I have 7 rows in the database.

home

lounge_bar

club_music

whats_on

menues

corporate_rooms

contacts

 

I want to echo out two at a time, depending on which page the

user is currently on.

 

the names are going to make up a bread crumbing effect.

 

FOR EXAMPLE:

home > menues

 

 

So, i'm trying to put the values into an array, where i can

then select which values i want.

 

FOR EXAMPLE:

echo $array['0'].' > '.$array['5'];

 

My knowledge on arrays is very limited as i don't tend to use them.

But i thought this would be a simple exercise to get me started.

 

Thanks for your help.

 

Link to comment
Share on other sites

$sql3 = "SELECT * FROM pages WHERE page_cat='bread_crumb'";
$select_query3 = mysql_query($sql3) or die ('error1');
$count3 = mysql_num_rows($select_query3);
while($row3 = mysql_fetch_assoc($select_query3))
{
$array[] =  $row3['page_name']; // this will fill $array with all the page names
}

print_r($array);
// prints out Array([0]=>Home, [1]=>lounge_bar, [2]=>club_music, [3]=>whats_on, [4]=>menues, [5]=>corporate_rooms, [6]=>contact)

echo $array['0'].' > '.$array['5'];
//echoes out Home>corporate_rooms

 

hope that helps

 

 

 

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.