Page 1 of 2
Lost table connection
Posted: Wed Jun 06, 2007 10:14 am
by seth_web
Hi, I am a php beginner. I was working on a project when I realized that I could not connect to one of my tables.
This is the query I used:
Code: Select all
$querry2 = "SELECT * FROM calc ";
$result2 = MYSQL_QUERY($querry2) or die ('Error: '.mysql_error ());
I have two other tables that are connecting fine. I checked to make sure that I was using
the proper name when calling the table. Not getting any error messages. I would appreciate any help.
Posted: Wed Jun 06, 2007 11:58 am
by superdezign
What's the error?
Posted: Wed Jun 06, 2007 12:49 pm
by volka
superdezign wrote:What's the error?
seth_web wrote:Not getting any error messages.
So, let's add more ouput. Please try.
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('mysql.trace_mode', true);
$query2 = "SELECT * FROM calc ";
echo '<div>Debug: ', $xghikj, ' <br /> ', $query2, "</div>\n";
$result2 = MYSQL_QUERY($query2) or die ('Error: '.mysql_error());
echo '<div>Debug: ', mysql_num_rows($result2), " rows</div>\n";
Posted: Wed Jun 06, 2007 1:16 pm
by Benjamin
Posted: Wed Jun 06, 2007 3:42 pm
by seth_web
I am not sure what the code does that volka gave me.
This is what the page is displaying:
Debug:
Notice: Undefined variable: xghikj in C:\wamp\www\Matrix\turtletop.php on line 31
SELECT * FROM calc
Debug: 1 rows
Posted: Wed Jun 06, 2007 4:26 pm
by superdezign
Looks as though the table's working fine. It only has one record in it though.
Is that correct?
Posted: Wed Jun 06, 2007 4:45 pm
by seth_web
Yes, the table has only one row.
Posted: Wed Jun 06, 2007 4:50 pm
by Weirdan
Yes, the table has only one row.
So what's the problem then?
Posted: Wed Jun 06, 2007 4:52 pm
by seth_web
I can not connect to the table. I can get the others, but not this one.
Posted: Wed Jun 06, 2007 4:55 pm
by superdezign
But... You can connect to the table.
Are you not getting your results?... I'm beginning to think you're going to need to show more code.
Posted: Wed Jun 06, 2007 5:09 pm
by RobertGonzalez
Just to clarify, you connect to a table, you connect to a server, use a database and select/insert/update/delete in/from tables.
Your query is working fine. volka's code showed that. It is also why you are not getting any error messages.
That said, what is your problem? You can obviously connect to the database server, you can obviously use a database and can obviously select from the table. What is not happening that you think should be?
Posted: Wed Jun 06, 2007 8:59 pm
by seth_web
I put the data into a variable and use if isset(). It returns that the variable is not set.
Posted: Thu Jun 07, 2007 5:40 am
by volka
Show... us... the... code
please
Posted: Thu Jun 07, 2007 7:02 am
by seth_web
Here is the code:
Code: Select all
while ($fr1 = mysql_fetch_array($result1, MYSQL_NUM)) {
while ($fr2 = mysql_fetch_array($result2, MYSQL_NUM)) {
if ($fr1[3] == 'Gas') {
$fd = $fr2[2];
}
elseif ($fr1[3] == 'Diesel') {
$fd = $fr2[3];
}
}
if (!isset($fd)) {
$fd = 'not set';
}
echo $fd;
}
Posted: Thu Jun 07, 2007 7:09 am
by feyd
A query loop within a query loop is often a road fraught with trials and tribulations.
Either cache the inner loop into an array, reset its pointer using
mysql_data_seek() or engineer your query to not need two queries (the preferred solution.)