just a simple array !!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

just a simple array !!!

Post by joecrack »

THIS SIMPLE #$%^&* does not work.

Code: Select all

<html><head>
<title>Datensatz löschen</title>
</head>
<body>
<?php;
error_reporting(E_ALL);

$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());
$sql = "SELECT * FROM sam_artikel";
$result=mysql_query($sql);
$zeile=mysql_fetch_array($result);

echo "<p>{$zeile['eqdes']} - {$zeile['designer']} - {$zeile['value']} - {$zeile['beschreibung']} - {$zeile['eqdesignation']}</p>";

mysql_close();
?>

</body></html>
PLZ HELP
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

error code?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

One armed space goat wrote:error code?
furthurmore.. change

Code: Select all

$result=mysql_query($sql);
to

Code: Select all

$result=mysql_query($sql) or die(mysql_error());
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

There is nothing just a blank page.
Also if i write

$result=mysql_query($sql) or die(mysql_error());

like you said - NOTHING
joe
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check what $zeile actually is:

Code: Select all

var_export($zeile);
if you see anything other than an array definition, your query contained no results.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Are you sure you have display errors on?

Code: Select all

ini_set('display_errors', 1);
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

Hai
i have display errors ON, i looked in the php.ini and also (i have xampp) the is a phpinfo page - also ON.
But i tried the script once with a wrong db name and no error appears !?!
Perhaps its display_startup_errors (i dont know what it is) its turned off !
I changed the code like this:

Code: Select all

<html><head>
<title>Datensatz löschen</title></head>
<body>
<?php;
error_reporting(E_ALL);
$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());

$sql = "SELECT * FROM sam_artikel";
$result=mysql_query($sql) or die(mysql_error());
$zeile=mysql_fetch_array($result);

var_export($zeile);
echo "{$zeile['eqdes']} - {$zeile['designer']} - {$zeile['value']} - {$zeile['beschreibung']} - {$zeile['eqdesignation']}";
mysql_close();
?>
</body></html>
Also with the var_export ... NOTHING again just a blank site.
I dont know what the hell is going on.
joe
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Check your PHP error logs.. from what I can tell it is a parse error. Also, double check when viewing the page that NO source code is displaying.[/list]
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

Theres nothing new in the error log ... just some errors 1 day old/.
THere realy is nothing i checked it a hundret times!!!
TJ
Forum Newbie
Posts: 20
Joined: Thu Nov 03, 2005 10:22 pm
Location: Nottingham, UK

Post by TJ »

How about adding a check on how many records have been returned from the query, so you know there 's something to print?

Code: Select all

$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());
$sql = "SELECT * FROM sam_artikel";
$result=mysql_query($sql);

echo 'Rows returned: '. mysql_num_rows($result); // check for results

$zeile=mysql_fetch_array($result);

echo "<p>{$zeile['eqdes']} - {$zeile['designer']} - {$zeile['value']} - {$zeile['beschreibung']} - {$zeile['eqdesignation']}</p>";

mysql_close();
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

NOTHING
when i insert:
echo 'Rows returned: '. mysql_num_rows($result);
still a blank page.
and its not like my php does not work.
other skips are working!!!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

change

Code: Select all

<?php;
To:

Code: Select all

<?php
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

At least its printing out something:

Code: Select all

$zeile=mysql_fetch_array($result);
But still not working!!?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

print_r($zeile);

or, try the mysql_error() from $result
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

Finally OMG
its really printing out the first dataset.
This is the script right now:

Code: Select all

<?php
error_reporting(E_ALL);

$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());

$sql = "SELECT * FROM sam_artikel" or die ("MySQL-Fehler: " . mysql_error());
$result=mysql_query($sql) or die(mysql_error());
$zeile=mysql_fetch_array($result);


echo "{$zeile['eqdes']} - {$zeile['designer']} - {$zeile['value']} - {$zeile['beschreibung']} - {$zeile['eqdesignation']}";


mysql_close();
?>
But now i would like it to print out all the datasets nut just the first one!
can i do that with: $rows=mysql_num_rows($query); and than i print all rows out with WHILE... ???
Post Reply