Lost table connection

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

seth_web
Forum Newbie
Posts: 20
Joined: Wed Jun 06, 2007 10:00 am

Lost table connection

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What's the error?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

SELECT * FROM `calc`
seth_web
Forum Newbie
Posts: 20
Joined: Wed Jun 06, 2007 10:00 am

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Looks as though the table's working fine. It only has one record in it though.

Is that correct?
seth_web
Forum Newbie
Posts: 20
Joined: Wed Jun 06, 2007 10:00 am

Post by seth_web »

Yes, the table has only one row.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Yes, the table has only one row.
So what's the problem then?
seth_web
Forum Newbie
Posts: 20
Joined: Wed Jun 06, 2007 10:00 am

Post by seth_web »

I can not connect to the table. I can get the others, but not this one.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
seth_web
Forum Newbie
Posts: 20
Joined: Wed Jun 06, 2007 10:00 am

Post by seth_web »

I put the data into a variable and use if isset(). It returns that the variable is not set.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Show... us... the... code
please
seth_web
Forum Newbie
Posts: 20
Joined: Wed Jun 06, 2007 10:00 am

Post 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;
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.)
Post Reply