We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
SQL...; Confuzzled
Topic Started: Jun 10 2005, 03:46 PM (308 Views)
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
OK, I have an insert script I'm trying to set up, to insert a record into a database.

The PHP is as follows

Code:
 
<?
$usr = "OBSCURED";
$pwd = "OBSCURED";
$db = "OBSCURED";
$host = "OBSCURED";

$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if (!$cid) { print "ERROR: " . mysql_error() . "\n"; }

if ($_SERVER['REQUEST_METHOD'] == "GET") {

$sql = " SELECT * FROM OBSCURED_TABLE_NAME ";
$result = mysql_query($sql, $cid);
if (mysql_error()) { print "Database ERROR: $sql " . mysql_error(); }
}
echo $result;
?>


And a button with:

Code:
 
<form method = "GET" action = "view_table.php">
...
<input type="submit" value="View Table">


But, whenever I hit the VIEW TABLE button, I get "Resource id #3" as the only result.

Can someone fix this please? :angel:
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
A $result is a resource link. You need to plug that into mysql_fetch_array() to grab the actual data.
Offline Profile Quote Post Goto Top
 
Gornakle
Member
[ *  *  *  *  * ]
The mysql_query returns an identifier. You can use this identifier with a function such as mysql_fetch_assoc(). For instance:

Code:
 
while ($row = mysql_fetch_assoc($result)) {
  echo $row['id'] . '<br />';
}


echoes all ID's in the table.
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
Edit...Now I understand :P Thanks alot.
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
Hm. Sorry for the double post, just so people who've read this and may be able to help can see there's a new point.

I've now just been playing around trying to get it to put my results into a table...I'm probably doing it wrong, but I got this:

Code:
 
<?
$usr = "[FILTER]";
$pwd = "[FILTER]";
$db = "[FILTER]";
$host = "localhost";

$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if (!$cid) { print "ERROR: " . mysql_error() . "\n"; }

if ($_SERVER['REQUEST_METHOD'] == "GET") {

$sql = " SELECT * FROM [FILTER] ";
$result = mysql_query($sql, $cid);
if (mysql_error()) { print "Database ERROR: $sql " . mysql_error(); }
}
while ($row = mysql_fetch_assoc($result)) {
'<html>
<head>
 <title>Seeds</title>
</head>

<body>
 <center>
  <table columns = "2">
   <tr>
    <td>
     echo $row["FILTERED"]
    </td>
   </tr>
  </table>
 </center>
</body>
</html>';
}
?>


[FILTER] is just a value like
pie
but obviously, it's data relating to the table, so I don't want people to see it =)

The problem is with this that it gives nothing. If I replace the "s in the echo, with 's, I get a parse error.

Any help please? Thanks.

EDIT: Does it have something to do with RecordAsTable() or is that totally wrong?
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
Is this an insert or select? The only query is a SELECT.
Offline Profile Quote Post Goto Top
 
FearKiller
Member Avatar
www.drewscripts.com
[ *  *  *  *  * ]
During the while loop your switching to HTML without first ending PHP. Here's one way to do it.
Code:
 
while ($row = mysql_fetch_assoc($result)) {
?>
<html>
<head>
<title>Seeds</title>
</head>

<body>
<center>
 <table columns = "2">
  <tr>
   <td>
    <?= $row['FILTERED'] ?>
   </td>
  </tr>
 </table>
</center>
</body>
</html>
<?php
}
?>
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
Thankies mucho. All sorted now :D

Mod/Admin can lock/trash/delete this, I don't need it any more.

Thanks to Seth and TheBalrog for helping in varying amounts, and FearKiller and Gornakle for providing answers :)
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply