Jump to content

Functions do not seem to be working.


fizzzgigg

Recommended Posts

Here is the script live [a href=\"http://www.neweyes.org/findnew.php\" target=\"_blank\"]Click Here[/a]

The code is [code]<?
function displaystateinfo1() {
    
    $columns = 5;
    //change the query to get another field from the database
    $query = "SELECT DISTINCT state FROM church ORDER BY state";
    $result = mysql_query($query);
    $num_rows = mysql_num_rows($result);
    $rows = ceil($num_rows / $columns);
    while($row = mysql_fetch_array($result)) {
    $data[] = $row['state'];
    //store the other field into an array
    
    }
    for($i = 0; $i < $rows; $i++) {
{
    echo "<tr valign=bottom>";
    echo "<td bgcolor=#2172A1 colspan=5><img src=img/blank.gif width=1 height=1></td>";
    echo "</tr>";
}
    echo "<TR valign=center>";
    for($j = 0; $j < $columns; $j++) {
    if(isset($data[$i + ($j * $rows)])) {
    echo "<td class=tabval><b><a href=findnew.php?state=".$data[$i + ($j * $rows)].">" . $data[$i + ($j * $rows)] . "</a></b></td>";
}
}
    echo "</TR>";
}
    echo "<tr valign=bottom>";
    echo "<td bgcolor=#2172A1 colspan=5><img src=img/blank.gif width=1 height=8></td>";
    echo "</tr>";
}

function displaycityinfo() {
    
    $columns = 5;
    //change the query to get another field from the database
    $query = "SELECT DISTINCT city,state FROM church WHERE state='$state' ORDER BY city";
    $result = mysql_query($query);
    $num_rows = mysql_num_rows($result);
    $rows = ceil($num_rows / $columns);
    while($row = mysql_fetch_array($result)) {
    $data[] = $row['city'];
    //store the other field into an array
    
    }
    for($i = 0; $i < $rows; $i++) {
{
    echo "<tr valign=bottom>";
    echo "<td bgcolor=#2172A1 colspan=10><img src=img/blank.gif width=1 height=1></td>";
    echo "</tr>";
}
    echo "<TR valign=center>";
    for($j = 0; $j < $columns; $j++) {
    if(isset($data[$i + ($j * $rows)])) {
    echo "<td class=tabval><b><a href='findnew.php?state=".$state."&city=" . $data[$i + ($j * $rows)] . "'>" . $data[$i + ($j * $rows)] . "</a></b></td>";
}
}
    echo "</TR>";
}
    echo "<tr valign=bottom>";
    echo "<td bgcolor=#2172A1 colspan=10><img src=img/blank.gif width=1 height=8></td>";
    echo "</tr>";

}

function displaychurchinfo(){
    $columns = 3;
    //change the query to get another field from the database
    $query = "SELECT DISTINCT city,state,name,id FROM church WHERE state='$state' and city='$city' ORDER BY name";
    $result = mysql_query($query);
    $num_rows = mysql_num_rows($result);
    $rows = ceil($num_rows / $columns);
    while($row = mysql_fetch_array($result)) {
    $data[] = $row['name'];
    $data1[] = $row['id'];
    //store the other field into an array
    
    }
    for($i = 0; $i < $rows; $i++) {
{
    echo "<tr valign=bottom>";
    echo "<td bgcolor=#2172A1 colspan=8><img src=img/blank.gif width=1 height=1></td>";
    echo "</tr>";
}
    echo "<TR valign=center>";
    for($j = 0; $j < $columns; $j++) {
    if(isset($data[$i + ($j * $rows)])) {
    echo "<td class=tabval><b><a href=churches.php?id=" . $data1[$i + ($j * $rows)] . ">" . $data[$i + ($j * $rows)] . "</a></b></td>";
}
}
    echo "</TR>";
}
    echo "<tr valign=bottom>";
    echo "<td bgcolor=#2172A1 colspan=8><img src=img/blank.gif width=1 height=8></td>";
    echo "</tr>";

}
function oldway() {
    $result=mysql_query('SELECT DISTINCT state FROM church');
    
    $i=0;
    while( $row=mysql_fetch_array($result) )
    {
        if($i>0)
        {
            echo "<tr valign=bottom>";
            echo "<td bgcolor=#2172A1 colspan=6><img src=img/blank.gif width=1 height=1></td>";
            echo "</tr>";
        }
        echo "<tr valign=center>";        
        echo "<td class=tabval><b><a href=findnew2.php?state=".$row['state'].">".$row['state']."</a></b></td>";
        echo "<td class=tabval></td>";
        echo "</tr>";
        $i++;

    }

    echo "<tr valign=bottom>";
        echo "<td bgcolor=#2172A1 colspan=9><img src=img/blank.gif width=1 height=8></td>";
        echo "</tr>";
}


if (isset($state)) {
displaycityinfo($state);
}
if (isset($city)) {
displaychurchinfo($state);
}
else {
displaystateinfo1();
}

?>[/code]

It needs to only show the cities when you click a state in the beginning and then show the the churches to the city you selected. I have it working through three separate pages [a href=\"http://www.neweyes.org/find.php\" target=\"_blank\"]Working version[/a] , but I am trying to narrow things down to one page so I can make a module to work with phpnuke.
Link to comment
https://forums.phpfreaks.com/topic/11734-functions-do-not-seem-to-be-working/
Share on other sites

fizzzgigg --

Your code is very long & to debug it I would have to compile it myself & work on it (unfortunately I don't have this kind of time). BUT -- my jerry-rigged version of debugging is a multi-step process I'll share.

1) Step away from the computer, take a little walk, have a soda or a beer & clear your head for a few minutes. All the little $&"; characters run together after a while. Seriously, this is my most valuable step in figuring out errors. On my most recent project where I have had to really push the envelope on my coding skills, I have worked on a little problem for HOURS, then taken a break & sat back down to realize it was a typo the whole time.

2) Come back to the computer and read through your code step-by-step, making sure there isn't an illogical step somewhere.

3) Add echo statements at each step throughout the code to see where the code is stopping/breaking. I have found this to help me a lot. Example: always put echo statement before your WHILE statements in your code to figure out if it isn't finding anything & there is something wrong with the query. Echo back your queries, echo back sent variables (another problem I have often -- I have sent a variable incorrectly) at every step in your functions & other code.

4) Consider whether there is a more efficient/logical way to arrange your code. If not, try steps 1-2 again.

Wendy

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.