in PHP...
At least that's what I think I have to do.
This is the code:
code:
function getPage($pageName){
Global $connection;
hookUpDb();
if($pageName != ""){
$query = "SELECT page_id,page_type,page_name
FROM pages WHERE page_name = '$pageName'";
} else {
$query = "SELECT page_id,page_type,page_name
FROM pages";
}
$result = mysql_query($query,$connection);
$page = mysql_fetch_array($result);
return $page;
mysql_free_result($result);
mysql_close($connection);
}
I've got this in one include, then I call it from a presentation page like this:
$page = getPage($pageName);
And print what I need from it like this:
echo "<br><br>\n<strong>".$page["page_id"]."</strong><br />\n";
echo "<strong>".$page["page_type"]."</strong><br />\n";
echo "<strong>".$page["page_name"]."</strong><br />\n";
Now, this works fine as long as I pass a valid page name to the function getPage($pageName);.
However, I need to be able to NOT send a page name to the function and get all pages that exist in the database returned, exactly like with the page name.
As it stands today, I only get the first row from the result-set back if I leave the page-name out. (Nothing strange about that)
The SQL is correct, and the getPage() function will loop and print everything IF I do a regular
code:
while ($page = mysql_fetch_row($result)){
print($page[page_id]."<br>");
print($page[page_type]."<br>");
print($page[page_name]."<br>");
}
inside the function, but I don't want that, I want it returned to wherever I call it from so I can work with it there!
So, I'm thinking that I might have to loop it and create something like this:
code:
(pseudo-code below...)
function getPage($pageName){
Global $connection;
hookUpDb();
if($pageName != ""){
$query = "SELECT page_id,page_type,page_name
FROM pages WHERE page_name = '$pageName'";
} else {
$query = "SELECT page_id,page_type,page_name
FROM pages";
}
$result = mysql_query($query,$connection);
while ($page = mysql_fetch_row($result)){
$pages[0] holds array page_1[page_id]]
page_1[page_type]
page_1[page_name]
$pages[1] holds array page_2[page_id]
page_2[page_type]
page_2[page_name]
}
return $pages;
mysql_free_result($result);
mysql_close($connection);
}
This example of course won't work, but am I going in the right direction?
I can't make heads or tails of the examples on multi-dimensional arrays in the php-manual, I've never worked with anything but the simplest arrays before so I'm lost :-(
Then, how would I read from this in order to get what I want from the "inner" array?
I hope this post is understandable...
Thanx/Dan
{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-
[This message has been edited by DmS (edited 06-07-2002). FumbleFingers...]
[This message has been edited by DmS (edited 06-07-2002).]