Page 1 of 1
Need help writing script. (Newbie)
Posted: Sun Aug 18, 2002 3:28 pm
by Zoram
I need help writing a script for a site I am designing...
This is what the script needs to do...
On the main page of the site there is a map of a couple of states, I need it so that when one of the states is clicked on you are taken to a page that displays the name of the state and lists the areas that are in that state.
Then I need it so that when you click on the area it brings up a page with a listing of the events listed in the database for that region. It also needs to bring up a listing of all articles from that area.
Then when you click on the article it brings up a page with that article...
Does anyone want to help me? This is really the first time I've used php and am trying to learn the coding... I've got the general idea but don't know how to set it up.
Posted: Sun Aug 18, 2002 4:40 pm
by phpPete
I'll pseudo-code this for you.
1) Main page ( index.html or what ever you named it )
Make your images image-maps with hot areas. Here is a good tutorial from
HTML Goodies
2)
Each hot area has a url defined in the image map. Something like:
Code: Select all
<map name="sample">
<area shape="iowa" coords="20,27,82,111" href="showStateData?state=IA">
</map>
The effect of clicking on that places IA into the $_GET array where the string index of the $_GET array is 'state' : $_GET['state']
3)
On the the page named:
showStateData.php you'll have some code like this:
Code: Select all
$sql = "SELECT area FROM states WHERE state_name = '" . $_GETї'state'] . "'";
// make your DB connection and query the DB
$link = mysql_connect( "localhost", "username", "password" )
or die("Could not connect");
$result = mysql_query($sql, $link ) or die( mysql_error());
while( $row = mysql_fetch_array( $result ))
{
//place the enitre result set into the $row array
$rowї'area']ї] = $rowї'area'];
}
4)
with the $row array full of the areas, you can now loop throuhg the $row array and generate active ( clickable ) links
Code: Select all
$arrLength = sizeof( $rowї'area'] );
//open a table outside of the loop
<table>
for ( $i = 0; $i < $arrLength; ++$i )
{
?>//jump out of PHP to write the HTML, then jump back in
<tr><td><a href="http://showAreaEvents.php?area="<?php echo $rowї'area']ї$i] ?>"</a></td></tr>
<?php // jump back in here
}// close the loop here
</table>
When you click onone of the new links, you repeat the process on the next page, only with different values in your query.
That's the gist of it.
For a more indepth Tutorial etc check out
Devshed or
SitePoint
And of course, scour this site too!!!
Good luck!
Thank You
Posted: Sun Aug 18, 2002 5:35 pm
by Zoram
Thank you for your help, I will work with this and see if I can't get it to work. Thank You!
Posted: Sun Aug 18, 2002 6:36 pm
by phpPete
My pleasure.
Posted: Sun Aug 18, 2002 6:57 pm
by HUWUWA
You are awesome phpPete !

Posted: Sun Aug 18, 2002 9:01 pm
by phpPete
Thanks, but hardly. I'm wrong more than I'm right. But sometimes i'm right..

Posted: Sun Aug 18, 2002 9:21 pm
by Zoram
I just have one problem that I can't fix right now...
I was working on the article page and I had thought to make just one table for all my articles, then just have the showArticle.php page select the state and area from all article and display the ones in that area. I've got it all but when I put
Code: Select all
WHERE 'state' = '". $_GETї'state'] ."' & 'area' = '". $_GETї'area'] ."'
on the sql select statement then it doesn't display anything, but when I take it off it shows all the articles...
I then tried just the
Code: Select all
WHERE 'state' = '". $_GETї'state'] ."'
And it worked for the state, then I did it the other way and it did it for the area, my question... how do i do both?
Posted: Sun Aug 18, 2002 9:30 pm
by phpPete
Relevant link: http://www.mysql.com/doc/en/Logical_Operators.html
In MySQL the logical operators for 'and' are:
&&
AND
respectively.
So change & to && and that should (

) do it.
PAS
DOH!
Posted: Sun Aug 18, 2002 10:16 pm
by Zoram
DOH! I forgot about operators! Thanks for your help...
Just one more thing I wanted to know...
How do you make it so that every other output had a different color for the background? Like a darker background on every other one?
Thanks again!
Posted: Sun Aug 18, 2002 10:34 pm
by phpPete
Code: Select all
$bgcolor = "#FFFFFF"; //white
$val = sizeof( $row ); // the size of the your $row array
for( $i = 0; $i < $val; ++i )
{
if( $i % $val == 0 )
{
$bgcolor = "#C0C0C0";
<tr bgcolor="$bgcolor"><td>_____</td></tr>
}
}
% is the remainder operator, called modulous
It returns the remainder after division
So 9 % 3 yields 0 // no remainder
15 % 7 yields 1 // remainder of one