Jump to content
php.lv forumi

Par ID


goma smile

Recommended Posts

Tad, kad dabū to skaitli kādā mainīgajā $id, tad arī pārbaudi attiecīgi kā tev tie dati glabājas. Piemēram, ja tas ir kādas tabulas atslēga, tad:

SELECT COUNT(*) FROM tabula WHERE id = $id

Ja atgriež 0, tad tāda id nav.

Link to comment
Share on other sites

$poll_check = mysql_query("SELECT poll_id FROM polls ");

 

while ($pid = mysql_fetch_assoc($poll_check)) 
{
$kautkas = $pid['poll_id'];
} 


IF ($_GET['id'] == $kautkas) {
echo "ir";
}else {
echo "nav";
}

 

 

Ar šito parāda ka eksistē tikai pēdējā, a pārējos rāda ka nav

Edited by goma smile
Link to comment
Share on other sites

Paklau, tev kļūdu rādīšana php ir atslēgta vai kā? Ieliec visu skriptu sākumā šo:

error_reporting(E_ALL);
ini_set("display_errors", 1);

Citādi jau programmēt takš nevar, ja nerāda kļūdas.

 

Tu kverijā selektē COUNT(*), taču no $pid velc ārā "poll_id" - tur tak nav tāda nosaukuma lauka. Lieto fetch_row un velc pirmo elementu ārā - būs vienkāršāk. Un while ciklu tev arī nevajag. Tev vajag tikai vienu fetch'u uztaisīt un viss.

Link to comment
Share on other sites

Eh... ka tu nelasi, ko tev saka.

$poll_id = (int)$_GET['id'];
$poll_check = mysql_query("SELECT COUNT(*) FROM polls WHERE poll_id=$poll_id") or die(mysql_error());
list($count) = mysql_fetch_row($poll_check);
if ($count == 0)
{
echo "nav";
}
else
{
echo "ir";
}

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...