Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2004, 03:23 PM
Registered User
 
Join Date: Dec 2003
Location: Fairfax, Vermont, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default MySQL Query Problem w/ PHP

Hello All,
I have this file I am using to access MySQL, it works on PHP 4.0.6 and MySQL 3.23.41. I now have Fedora 2 loaded on another machine and I cannot seem to get the same program to work. On Fedora 2 I have PHP 4.3.8, MySQL 3.23.58. My form appears fine in the screen and I see my variable populated in the URL bar on the top of the web browser. I have even added an echo statement to echo the variable on the .php page. I get the html displayed on the screen, but none of the info.

So here is a bit of the code. I have omitted the html tags so the post won't get to large.

//Defining the form and where to go.
echo "<form method='GET' enctype='multipart/form-data' action='./test_query.php'>";

//Query section

    $query = "SELECT cell_num FROM clchvt WHERE cell_technology = 'tdma' ORDER BY cell_num ASC";

    $link_id = db_connect('clchvt_db');
    $result = mysql_query($query, $link_id) or die (mysql_error());

        WHILE ($query_data = mysql_fetch_array($result))
        {
            $cell_num = $query_data["cell_num"];

            echo "<option>$cell_num</option>";
    $result;
        }

//Here is the test_query.php section of the file. The file is quiet large, I figure if I can get the first section straightened out the rest will work out. I have three tables I pull info from.

if ($TDMA_CellNum != "TDMA_Num")
   {

      $query = "SELECT * FROM clchvt WHERE cell_technology = 'tdma' AND cell_num = '$TDMA_CellNum'";

   }
elseif ($TDMA_CellName != "TDMA_Name")
   {
     $query = "SELECT * FROM clchvt WHERE cell_technology = 'tdma' AND cell_name = '$TDMA_CellName'";

   }



    $link_id = db_connect('clchvt_db');
        $result = mysql_query($query, $link_id) or die (mysql_error());

        $query_data = mysql_fetch_array($result);

            $cell_num = $query_data["cell_num"];
                        $cell_name = $query_data["cell_name"];
                        $cell_loc = $query_data["cell_loc"];
                        $cell_type = $query_data["cell_type"];
                        $cell_technology = $query_data["cell_technology"];
                        $rsa = $query_data["rsa"];
                        $cell_tech = $query_data["cell_tech"];
                        $freq_grp = $query_data["freq_grp"];
                        $hand_held = $query_data["hand_held"];
                        $pager_num = $query_data["pager_num"];
                        $truck_num = $query_data["truck_num"];

//---------------------------------------------------------------------------//
//collect info from the license table. long, lat, antenna info.--------------//
//---------------------------------------------------------------------------//

    $query = "SELECT * FROM license WHERE cell_num2 = '$cell_num'";

        $link_id = db_connect('clchvt_db');
        $result = mysql_query($query, $link_id) or die (mysql_error());

        $query_data = mysql_fetch_array($result);

            $cell_lat = $query_data["cell_lat"];
                        $cell_long = $query_data["cell_long"];
            $antenna_type = $query_data["antenna_type"];
                        $orient = $query_data["orient"];
            $centerline = $query_data["centerline"];
            $e911_addr = $query_data["e911_addr"];
                        $city = $query_data["city"];
            $county = $query_data["county"];
                        $state = $query_data["state"];
            $market_name = $query_data["market_name"];
                        $market_number = $query_data["market_number"];
            $license_name = $query_data["license_name"];
                        $call_sign = $query_data["call_sign"];

//-----------------------------------------------------------------------------//
//----Layout of the html for the webpage. results of the query are output ------//
//---from here. If the site has more than one t-1 the table listings are--------//
//---below.---------------------------------------------------------------------//
echo $TDMA_CellNum;
            echo "<div align='center'>";
                        echo "<table border='1' cellspacing='8' width='700' bgcolor='#5fa4ee'>";
                        echo "<caption>Cell DB, $cell_name</caption>";
                        echo "<tr>";
                        echo "<th>Cell Site Number</th>";
                        echo "<th>Cell Site Name</th>";
                        echo "<th>Cell E-911 Address</th>";
                        echo "<th>City or Town</th>";
                        echo "</tr>";
                        echo "<tr>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $cell_num;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $cell_name;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $e911_addr;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $city;
                        echo "</td>";
                        echo "</tr>";
            echo "<tr>";
                        echo "<th>County</th>";
                        echo "<th>State</th>";
                        echo "<th>Market Name</th>";
            echo "<th>Market Number</th>";
            echo "</tr>";
                        echo "<tr>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $county;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $state;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $market_name;
                        echo "</td>";
            echo "<td align='center' bgcolor='e4e890'>";
                        echo $market_number;
                        echo "</td>";
                        echo "</tr>";
                        echo "<tr>";
                        echo "<th>Cellular Technology</th>";
                        echo "<th>Cell Equipment</th>";
                        echo "<th>License Name</th>";
                        echo "<th>Call Sign</th>";
            echo "</tr>";
                        echo "<tr>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $cell_technology;
                        echo "</td>";
            echo "<td align='center' bgcolor='e4e890'>";
                        echo $cell_type;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $license_name;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $call_sign;
                        echo "</td>";
                        echo "</tr>";
            echo "<tr>";
                        echo "<th>Latitude</th>";
                        echo "<th>Longitude</th>";
                        echo "<th>Antenna Type</th>";
            echo "<th>Antenna Orientation</th>";
                        echo "</tr>";
                        echo "<tr>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $cell_lat;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $cell_long;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $antenna_type;
                        echo "</td>";
            echo "<td align='center' bgcolor='e4e890'>";
                        echo $orient;
                        echo "</td>";
                        echo "</tr>";
            echo "<tr>";
                        echo "<th>Centerline (m)</th>";
                        echo "<th>ERP (w)</th>";
                        echo "</tr>";
                        echo "<tr>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $centerline;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $erp;
                        echo "</td>";
                        echo "</tr>";
                        echo "<tr>";
                        echo "<th>Technician Name</th>";
                        echo "<th>Hand Held</th>";
                        echo "<th>Pager Number</th>";
                        echo "<th>Truck Number</th>";
                        echo "</tr>";
                        echo "<tr>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $cell_tech;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $hand_held;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $pager_num;
                        echo "</td>";
                        echo "<td align='center' bgcolor='e4e890'>";
                        echo $truck_num;
                        echo "</td>";
                        echo "</tr>";
                        echo "</table>";
                        echo "</div>";
                     $result;

Thanks,
RD
 
Old August 27th, 2004, 03:55 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You no longer need to specify a link parameter for mysql_query. Also, instead of db_connect, try mysql_connect() and mysql_select_db().

http://www.php.net/mysql-query
http://www.php.net/mysql-select-db
http://www.php.net/mysql-connect

I hope this solves your problem.

Snib

<><
 
Old August 27th, 2004, 04:51 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:
You no longer need to specify a link parameter for mysql_query. Also, instead of db_connect, try mysql_connect() and mysql_select_db().
A link parameter is a good thing to specify, what if you add a second database connection? db_connect looks like a custom defined DB abstraction function, yet another good thing. These are unlikely to be the problem.

PHP 4.0.6 is pre register_globals = off, so check the variables that would be affected by this.

http://www.google.com/search?q=regis...e:p2p.wrox.com

What errors are you seeing? What is error_reporting set at?

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
 
Old August 28th, 2004, 04:57 PM
Registered User
 
Join Date: Dec 2003
Location: Fairfax, Vermont, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good Afternoon,
I reviewed the commands and made the modifications. The first file works, now I am working on the second file. It appears that the variable is not being passed. I tried a echo $var command and the screen is blank. I bit more reading is needed I suppose.
If I cannot figure it out I will return with more questions.

Thanks,
RD
 
Old August 29th, 2004, 09:48 AM
Registered User
 
Join Date: Dec 2003
Location: Fairfax, Vermont, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good Morning All,
Well, I have been reading and trying a few different things. In a couple of posts about variables I tried the isset function with not much success. The variable is not passed from the first page where the selection is made.
Here is what the second page looks like from the testing I am doing. I have not got to the point where I am trying to call data from the db yet.
Here is what works so far. Hello shows up, as well as successfully connected. The display of the variable is not being displayed. I am confused about why I can query from the first form and get info, but why when I get to the second form it will not show the variable at all when called.
In the common_db.inc I have some error reporting set but the screen was showing up blank. I have commented out the .inc file for the time being.

<?php
//test_query.php
//Search by cell site number or name
//Ron Mapes 2004

//include "common_db1.inc";
//mysql_select_db('clchvt_db');


    echo 'HELLO';
    echo '<br />';
    echo isset ($TDMA_CellNum);
    echo '<br />';

    if (isset ($TDMA_CellNum))
      {
       echo 'I see $TDMA_CellNum, but it will not display';
      }
        else
      {
        echo $TDMA_CellNum;
      }
    $link = mysql_connect('localhost', 'rondm', 'clchvt2');
          if (!$link)
            {
              die('Could not connect: ' . mysql_error());
            }
              echo 'Connected successfully';
          echo '<br />';



?>


Here is the first form where the variable is set. It appears that all is well on this one. The drop down selection works.

<?php
//test_search.php
//Search cell by number or name
//include "common_db1.inc";
//mysql_select_db('clchvt_db');

            echo "<html>";
            echo "<body>";
            echo "<div align='center'>";
            echo "<h1>RCC Atlantic Cell DB</h1>";
            echo "<h2>NOTE: A Work in Progress</h2>";
            echo "</div>";
            echo "<h4>Here is where you can search for site specific information based on cell number or cell name. If there are any problems or incorrect information please contact the switch room.</h4>";

            echo "<form method='GET' enctype='text/plain' action='./test_query.php'>";
            echo "<table width='225' cellspacing='25' border='5' cellpadding='5' align='center' bgcolor='gray' frame='box'>";
              echo "<caption>Search for a cell site</caption>";
              echo "<tbody align='center' valign='center' bgcolor='lightGray'>";

//---------------TDMA CELL NUMBER-------------------------------------------//
            echo "<tr>";
            echo "<td>";
            echo "<select name = 'TDMA_CellNum'>";
            echo "<option selected value = 'TDMA_Num'>TDMA</option>";

    $query = "SELECT cell_num FROM clchvt WHERE cell_technology = 'tdma' ORDER BY cell_num ASC";

    $link = mysql_connect('localhost', 'rondm', 'clchvt2');
          if (!$link)
            {
              die('Could not connect: ' . mysql_error());
            }
              echo 'Connected successfully';

    $db_selected = mysql_select_db('clchvt_db', $link);
          if (!$db_selected)
        {
              die ('Can\'t use clchvt_db : ' . mysql_error());
            }

        $result = mysql_query($query);
      if (!$result)
            {
              die('Invalid query: ' . mysql_error());
            }

    WHILE ($query_data = mysql_fetch_array($result))
        {
            $cell_num = $query_data["cell_num"];

            echo "<option>$cell_num</option>";
    $result;
        }

            echo "</select>";
             echo "</td>";

//--------------TDMA CELL NAME--------------------------------------//

            echo "<td>";
            echo "<select name = 'TDMA_CellName'>";
                        echo "<option selected value = 'TDMA_Name'>TDMA Cell Name</option>";

        $query = "SELECT cell_name FROM clchvt WHERE cell_technology = 'tdma' ORDER BY cell_name ASC";

       $link = mysql_connect('localhost', 'rondm', 'clchvt2');
          if (!$link)
            {
              die('Could not connect: ' . mysql_error());
            }
              echo 'Connected successfully';

    $db_selected = mysql_select_db('clchvt_db', $link);
          if (!$db_selected)
        {
              die ('Can\'t use clchvt_db : ' . mysql_error());
            }

        $result = mysql_query($query);
      if (!$result)
            {
              die('Invalid query: ' . mysql_error());
            }

        WHILE ($query_data = mysql_fetch_array($result))
                {
                        $cell_name = $query_data["cell_name"];

                        echo "<option>$cell_name</option>";
        $result;
                }

                        echo "</select>";
            echo "</td>";
            echo "<tr>";
            echo "<td>";
            echo "<input type='submit' value='Search the DB' />";
            echo "</td>";
            echo "<td>";
            echo "<input type='reset' value='Reset All Fields' />";
            echo "</td>";
            echo "</tr>";
            echo "</table>";
            echo "</form>";
            echo "</body>";
                        echo "</html>";

?>

Being a novice can be stressfull?

Thanks,
RD
 
Old August 14th, 2010, 12:55 AM
deb deb is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question data filter

i've database stored in sql. now i want to retrive the data of particular date using php like 15.09.2001 to 23.10.2001. can anyone help me for this.




Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/MySQL Subquery Problem gfackler MySQL 1 April 18th, 2007 11:31 PM
php and mysql query ghari PHP Databases 1 February 12th, 2006 06:43 PM
problem in mysql php charset yoord BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 11th, 2005 03:40 AM
MySQL Query Problem cmiller Beginning PHP 4 August 26th, 2003 12:43 AM
problem with PHP - MYSQL in LINUX cnilashis PHP How-To 3 August 18th, 2003 02:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.