Page 1 of 1

cycle thru an array ( noob :(

Posted: Fri Jun 10, 2005 8:31 pm
by kennybunkport
Here's what I have:

Code: Select all

<?php

$buttons = &quote;Home,PC Information Center,PC Clinic,PC Learning Center,Log-in,About Us&quote;;

$links = &quote;/index.php,/Info_Ctr/info_home.html,/Clinic/clinic_home.html,/School/school_home.html,/login.php,/about.html&quote;;

$arrbuttons = split(&quote;,&quote;, $buttons);
$arrlinks = split(&quote;,&quote;, $links);

$lenbuttons = count($arrbuttons);
echo $lenbuttons;

for($i=0; $i<$lenbuttons; $i++)
{
echo &quote;<a href=&quote; . $arrbuttons&#1111;i] . &quote;>&quote; . $arrlinks&#1111;i] . &quote;</a></br>&quote;;
}
?>
I know this doesn't work. It's just what I tried.
This is experiment # 2 with PHP.

Also point me toward a more Noob forum. This place already makes me feel like a loser.

Posted: Fri Jun 10, 2005 8:54 pm
by Skara

Code: Select all

$buttons = "Home,PC Information Center,PC Clinic,PC Learning Center,Log-in,About Us";

$links = "/index.php,/Info_Ctr/info_home.html,/Clinic/clinic_home.html,/School/school_home.html,/login.php,/about.html";
 
$arrbuttons = explode(",", $buttons);
$arrlinks = explode(",", $links);
 
for($i = count($arrbuttons) - 1; $i >= 0; $i--) {
  echo "<a href=" . $arrbuttons[$i] . ">" . $arrlinks[$i] . "</a><br />";
}
Your main mistake was that the i inside arrays is a variable. You still need the $ in front.

[offtopic]<br />, not </br>. :P

Posted: Fri Jun 10, 2005 9:03 pm
by kennybunkport
Thanks.


Oh yeah in PHP id there a short cut to

Code: Select all

&quote; . chr(34) . &quote;
Sorry to ask more actually.
Um I noticed that reading an empty query causes an error.

index.php

without ?q=

Code: Select all

<?php
$q = $_GET&#1111;&quote;q&quote;];
?>
returns an error, but this is the 'index' page.
A user entering the site from DNS will have no string value.

Thanks if I'm asking too much.
I am looking around the web for this info too, but I figured I'd ask.

Posted: Fri Jun 10, 2005 10:37 pm
by Revan
use

Code: Select all

if(isset($_GET["q"])) 
{
    // stuff
}

Posted: Fri Jun 10, 2005 10:39 pm
by kennybunkport
Thanks!