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
Post
by seth_web » Wed Jun 06, 2007 10:14 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Jun 06, 2007 12:49 pm
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";
seth_web
Forum Newbie
Posts: 20 Joined: Wed Jun 06, 2007 10:00 am
Post
by seth_web » Wed Jun 06, 2007 3:42 pm
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
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Jun 06, 2007 4:26 pm
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 » Wed Jun 06, 2007 4:45 pm
Yes, the table has only one row.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Jun 06, 2007 4:50 pm
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 » Wed Jun 06, 2007 4:52 pm
I can not connect to the table. I can get the others, but not this one.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Jun 06, 2007 4:55 pm
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.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Jun 06, 2007 5:09 pm
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 » Wed Jun 06, 2007 8:59 pm
I put the data into a variable and use if isset(). It returns that the variable is not set.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Jun 07, 2007 5:40 am
Show... us... the... code
please
seth_web
Forum Newbie
Posts: 20 Joined: Wed Jun 06, 2007 10:00 am
Post
by seth_web » Thu Jun 07, 2007 7:02 am
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;
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 07, 2007 7:09 am
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.)