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
https://forums.phpfreaks.com/topic/54265-solved-array-help/
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
https://forums.phpfreaks.com/topic/54265-solved-array-help/#findComment-268288
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
https://forums.phpfreaks.com/topic/54265-solved-array-help/#findComment-268297
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
https://forums.phpfreaks.com/topic/54265-solved-array-help/#findComment-268307
Share on other sites

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.