For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > August 2004 > PHP and MySQL Queries having trouble









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PHP and MySQL Queries having trouble
JacKDynne

2004-08-18, 3:57 pm

TIA to anyone that can help me; I have a little problem and it goes
like this:

I have a php/mysql app that captures telephone calls via user entry,
all works fine except for this - when users check to see if the
caller has called before there is a query that lists previous callers
by using this: --------
query = mysql_query("select `FirstName` , `LastName`
from tracker ORDER BY `FirstName`") or
die(mysql_error());
--------

which when run directly against the db in mysql returns everything
fine but when returned to the web page that calls it in php will not
list those with the same last name or first name, depending on how I
structure the query.

Here are the relevant pieces of code (in the order that it's
called):

viewclient.php


--------
<?
session_start();
header("Cache-control: private");
if (_SESSION["loggedin"] != 1)
{
echo "Please login before trying to access this script.";
exit();
}
require("include/config.php");
include("templates/header.php");
connection = mysql_connect (host, user,
pass) or die(mysql_error());
mysql_select_db (db) or die
(mysql_error());
query = mysql_query("select `FirstName` , `LastName`
from tracker ORDER BY `FirstName`") or
die(mysql_error());
echo "<form name='frmClient' method='post'
action='clientid.php'>";
echo "<table><tr><td
class='formleft'>Please select a
client:</td>";
echo "<td class='formright'><select
name='client'>";
while (line = mysql_fetch_row(query))
{
if (prev != line[0] &&
prev2 != line[1])
{
_line[0] =
str_replace("","",line[0]);
_echo "<option>" . line[0] . "
" .
line[1] . "</option>";
}
prev = line[0];
prev2 = line[1];
}
echo
"</select></td></tr><tr><td
class='formleft'> </td><td
class='formright'>";
echo "<input type='submit' /> <input
type='reset'
/></td></tr></table>";
include("templates/resultsfoot.php");
--------

clientid.php:
--------
<?
session_start();
header("Cache-control:
private");
if (_SESSION["loggedin"] != 1)
{
echo "Please login before
trying to access this script.";
exit();
}
require("include/config.php");
include("templates/header.php");
connection = mysql_connect (host,
user,
pass) or die(mysql_error());
mysql_select_db (db) or die
(mysql_error());
names = explode(" ",client);
query =
mysql_query("select `index` , `Screening` from
tracker WHERE `FirstName` =
'names[0]' AND
_`LastName` = 'names[1]' ORDER BY
`index`") or
die(mysql_error());
echo "<form name='frmClient' method='post'
action='reports/client.php'>";
echo "<table><tr><td
class='formleft'>Please select a call
number:</td>";
echo "<td
class='formright'><select
name='callnumber'>";
while (line =
mysql_fetch_row(query))
{
if (prev != line[0])
{
_line[0] =
str_replace("","",line[0]);
_echo "<option>" . line[0] . " Date
entered: " . line[1] .
"</option>";
}
prev = line[0];
}
echo
"</select></td></tr><tr><td
class='formleft'> </td><td
class='formright'>";
echo "<input type='submit' /> <input
type='reset'
/></td></tr></table>";
include("templates/resultsfoot.php");
?>

--------

client.php:
--------
<?
ob_start("ob_gzhandler");
session_start();
header("Cache-control: private");
if (_SESSION["loggedin"] != 1)
{
echo
"Please login before trying to access this script.";
exit();
}
require("../include/config.php");
echo "<html style='overflow-x:
hide'>n<head>n<title>nWID
Call Trackingn</title>n<link
rel='stylesheet' type='text/css'
href='../stylesheet/style.css'
/>n</head>n<body>n<img
src='../images/header.jpg' alt=''
/>n<hr
style='color: black; height:
1px' />n";
connection = mysql_connect
(host, user,
pass) or die(mysql_error());
mysql_select_db (db) or die
(mysql_error());
id = explode(" ",callnumber);
query =
mysql_query("select * from tracker WHERE `index`
= 'id[0]'") or
die(mysql_error());
results = mysql_fetch_array(query) or
die(mysql_error());
index = 0;
cquery = mysql_query("select count(*)
from
descriptions") or die(mysql_error());
count = mysql_result(cquery,
0);
while(index != count)
{
results[index] =
str_replace("","",results[index]);

index = index + 1;
}
echo
"<table width='725' style='height:
70%' align='left'>n";
index2 = 1;
query2 = mysql_query("select `desc` from
descriptions") or
die(mysql_error());
while (line = mysql_fetch_row(query2))
{
line[0] =
str_replace("","",line[0]);
echo "n<tr>n<td
class='formleft'>n" .
line[0] .
"n</td>n<td
class='formright'>";
echo "n" .
results[index2] .
"n</td>n</tr>n";
index2 = index2 + 1;
}
include("../templates/resultsfoot.php");
?>
--------

Like I said, when I
run the query straight against the db it returns
all called just fine but
when it's run via the browser it does
not return any records that have the
same name, depending on the
ORDER BY order, in this case the firstname.

Any ideas??

I have asked on a few boards and have yet to get any replies
- will
keep on poring over the manual for more info but from what I have
read I am doing it right...

:)

/JD



----------------------------------------
The post originated from PHP
Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


mebil

2004-08-18, 3:57 pm

Well I don't know if your question has been answered/found but you
should have something like this for your querries.



db = "mysql_connect("HOST", "USERNAME",
"PASSWORD");
query = mysql_query("select `FirstName` , `LastName` from
tracker ORDER BY `FirstName`, db") or
die(mysql_error());



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


JacKDynne

2004-08-18, 3:57 pm

THanks much mebil :)

Trying it out now :ph34r:

/JD

Grrr not working - here is the full code from viewclient.php--------
<?
session_start();
header("Cache-control: private");
if (_SESSION["loggedin"] != 1)
{
echo "Please login before trying to access this script.";
exit();
}
require("include/config.php");
include("templates/header.php");
connection = mysql_connect (host, user,
pass) or die(mysql_error());
mysql_select_db (db) or die
(mysql_error());
query = mysql_query("select `FirstName` , `LastName`
from tracker ORDER BY `FirstName` ASC") or
die(mysql_error());
echo "<form name='frmClient' method='post'
action='clientid.php'>";
echo "<table><tr><td
class='formleft'>Please select a
client:</td>";
echo "<td class='formright'><select
name='client'>";
while (line = mysql_fetch_row(query))
{
if (prev != line[0] &&
prev2 != line[1])
{
line[0] =
str_replace("","",line[0]);
echo "<option>" . line[0] . "
" .
line[1] . "</option>";
}
prev = line[0];
prev2 = line[1];
}
echo
"</select></td></tr><tr><td
class='formleft'> </td><td
class='formright'>";
echo "<input type='submit' /> <input
type='reset'
/></td></tr></table>";
include("templates/resultsfoot.php");
?>
--------

Hope that helps clarify some :)

Please help :blink:



----------------------------------------
The post originated from PHP
Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com