Jump to content
php.lv forumi

Problēma ar datu saņemšanu no mysql


Hennikenno

Recommended Posts

Drošivien problēma ir izrunāta neskaitāmas reizes, bet tomēr vēlos uzzināt, kas manā kodā ir nepareizs:

 

<?php
require "core/core.php";

dbconn();

head("Charts");

echo"<h2>Charts</h2>";

$res = mysql_query("SELECT * FROM poll WHERE type = q ORDER BY id DESC");
if (mysql_num_rows($res) > 0) {
while($array = mysql_fetch_array($res)) {
$id = $array['id'];
echo"<div class=\"block\">";
$ip = sqlesc(getip());
$uvres = mysql_query("SELECT * FROM poll WHERE type = a AND ip = $ip");
if (mysql_num_rows($uvres) < 3) {
echo"<h3>".$array['question']."</h3><form>";
$pores = mysql_query("SELECT * FROM poll WHERE id = $id AND type = o");
while($poarr = mysql_fetch_array($pores)) {
echo"<input name=\"poll_$id_option\" type=\"radio\"> ".$poarr['option']."<br/>";
}
echo"<input type=\"submit\" name=\"Submit vote\"></form>";
}
else
{
echo"<h3>".$array['question']."</h3>";
$vores = mysql_query("SELECT * FROM poll WHERE type = o AND id = $id");
while($voarr = mysql_fetch_array($vores)) {
$option = $voarr['option'];
$uares = mysql_query("SELECT * FROM poll WHERE type = a AND option = $option");
$votes = 0;
while($uaarr = mysql_fetch_array($uares)) {
$votes = $votes + 1;
}
echo"$option - $votes votes on this!<br/>";
}
echo"You have already voted on this enaugh times!";
}
}
}
else
{
echo"<h3>No polls</h3>";
}

foot();

?>

 

CREATE TABLE IF NOT EXISTS `poll` (
 `id` int(10) default NULL,
 `type` enum('q','o','a') default NULL,
 `question` varchar(200) default NULL,
 `option` varchar(200) default NULL,
 `ip` varchar(100) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

 

 

Izpildot so kodu, viss ko saņemu ir:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\web\apache\htdocs\web2\top.php on line 11

No polls

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...