webForumDet fria alternativet

MySQL Error...!

4 svar · 323 visningar · startad av Guldstrand

GuldstrandMedlem sedan juli 20041 271 inlägg
#1

Jag har laddat ner ett färdigt php-script, men jag får det inte till att fungera riktigt. :(

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/PROTECTED/public_html/PROTECTED/index.php on line 109

Felet ska tydligen ligga i

while ($rows = mysql_fetch_array($query)){

Från index.php

<? 
$query = mysql_query("SELECT id,catname FROM db_cam_cat ORDER BY catname"); 
while ($rows = mysql_fetch_array($query)){ 
echo "<OPTION VALUE=\"$rows[id]\""; 
if ($sort == $rows[id]){ 
echo " SELECTED"; 
} 
$totalc = "SELECT id from db_cam WHERE cat = '$rows[id]' AND active = '1'"; 
$totalsc = mysql_query($totalc); 
$total_rowsc = mysql_num_rows($totalsc); 
echo ">$rows[catname] ($total_rowsc)\n"; 
} 
?>

Tabellen ser ut såhär:

CREATE TABLE db_cam_cat (
  id int(11) NOT NULL auto_increment,
  description varchar(255) default NULL,
  PRIMARY KEY  (id)
);

INSERT INTO db_cam_cat VALUES (1, 'Girls with Webcams', 'Webcams from different girls around the world...');
INSERT INTO db_cam_cat VALUES (2, 'Boys with Webcams', 'Webcams from different boys around the world...');
INSERT INTO db_cam_cat VALUES (3, 'Other Live Webcams', 'Webcams from different places around the world...');
INSERT INTO db_cam_cat VALUES (4, 'Online City Cams', 'Webcams from different citys around the world...');
INSERT INTO db_cam_cat VALUES (5, 'Animals & Zoo', 'Live cams around the world of animals and from Zoo\'s around...');
INSERT INTO db_cam_cat VALUES (6, 'Live beach cams', 'Online cams at seashores and beaches around the world...');
INSERT INTO db_cam_cat VALUES (7, 'Live Sex Cams', 'Live sex and nude cams around the world...');
INSERT INTO db_cam_cat VALUES (8, 'Live Boat Cams', 'Cams that are mounted on boat\'s around the world...');
INSERT INTO db_cam_cat VALUES (9, 'Live Wired Cams', 'Strange and Wired Cams around the world...');
INSERT INTO db_cam_cat VALUES (10, 'Live Airport Cams', 'Live cams from airports around the world...');

Hoppas att någon kan hjälpa mig att hitta felet!? :q

lunne82Medlem sedan dec. 2003153 inlägg
#2

Du har fel på frågan du skickar till databasen.

Ändra raden:
$query = mysql_query("SELECT id,catname FROM db_cam_cat ORDER BY catname");
till
$query = mysql_query("SELECT id,catname FROM db_cam_cat ORDER BY catname")or die(mysql_error());

GuldstrandMedlem sedan juli 20041 271 inlägg
#3

Det hjälpte inte...

Jag glömde tillägga att jag inte kan köra/skapa tabellen db_cam_cat i phpmyadmin heller. :r

Får även ett fel i phpmyadmin när jag ska "köra" tabellen.

SQL-fråga: 

INSERT INTO db_cam_cat
VALUES ( 1, 'Girls with Webcams', 'Webcams from different girls around the world...' ) 
MySQL sa:  

#1136 - Column count doesn't match value count at row 1
lunne82Medlem sedan dec. 2003153 inlägg
#4

Du har inte skapat någon kolumn i tabellen för, i ditt exempel ovan, 'Girls with Webcams'. Du använder nu:

CREATE TABLE db_cam_cat (
  id int(11) NOT NULL auto_increment,
  description varchar(255) default NULL,
  PRIMARY KEY  (id)
);

men du skulle behöva:

CREATE TABLE db_cam_cat (
  id int(11) NOT NULL auto_increment,
  name varchar(100) default NULL,
  description varchar(255) default NULL,
  PRIMARY KEY  (id)
);
K++Medlem sedan juli 2002171 inlägg
#5

Byt ut mysql_fetch_array mot mysql_fetch_assoc så borde det fungera..

139 ms totalt · 3 externa anrop · v20260731065814-full.0e50b1ef
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
135 ms — hämta tråd, inlägg och bilagor (db)