johanes Posted June 23, 2005 Report Share Posted June 23, 2005 (edited) <?php include $DOCUMENT_ROOT.'/wap/inc/header.php'; include $DOCUMENT_ROOT.'/wap/inc/db/config.php'; ####### if (empty($page)) $page = 0; if ($page < 0) $page = 0; $count_query = 'select count(*) from jaunumi where 1;'; $total_mess = mysql_query ($count_query); $total_count = mysql_fetch_array ($total_mess); $count = $total_count ['count(*)']; ########################################## $query = 'select * from jaunumi where 1 ORDER BY `date` DESC LIMIT '.$page.', '.$max_mess.';'; $result = mysql_query($query); if (!$result) { echo "Error! mysql_query".mysql_error(); exit; } echo "Jaunumi: ".$count; if ($count < 0) # Ja nav zinju neraada cik ierakstu { echo 'Nav neviena jaunuma!'; include $DOCUMENT_ROOT.'/wap/inc/end.php'; exit; } while ($i < $max_mess) # { $row_date = htmlspecialchars(mysql_result($result, $i, "date")); $row_message = htmlspecialchars(mysql_result($result, $i, "message")); $row_message = trim($row_message); if (empty($row_message)) break; echo "<br/>_________________________<br/>"; echo "".$row_date; echo "<br /><b>><> </b>".$row_message; echo "<br/><br/>"; $i++; } problēma ir tā ka izmet kļūdu Warning: mysql_result(): Unable to jump to row 1 on MySQL result index 4 in /index.php on line 32 Edited June 23, 2005 by johanes Link to comment Share on other sites More sharing options...
Grey_Wolf Posted June 23, 2005 Report Share Posted June 23, 2005 $count_query = 'select count(*) from jaunumi where 1;'; 'Paraadiit skaitu (visam) no tabulas jaunumi Ja 1' Izlasiji ? saprati? Mysql arii nesaprata. :( peec WHERE janoraada nosacijums !!! nevis kaads lielums piem ja: ieraksts laukss x=y :) -------- Prieciigus sveetkus un lai izdodas.... Link to comment Share on other sites More sharing options...
bubu Posted June 23, 2005 Report Share Posted June 23, 2005 Grey_Wolf, kverijs ir pareizs. WHERE 1 nozīmē to pašu, ko WHERE True, vai WHERE 1=1. Tb visas rindas (jēga gan nekāda), bet mysql to ļoti labi saprotīs un kļūdu nemetīs. johanes, šī vieta nav pareiza: $count_query = 'select count(*) from jaunumi where 1;'; $total_count = mysql_fetch_array ($total_mess); $total_mess = mysql_query ($count_query); $count = $total_count ['count(*)']; Vajag apmēram šādi: $count_query = 'select count(*) as skaits from jaunumi where 1;'; $total_mess = mysql_query ($count_query); $total_count = mysql_fetch_array ($total_mess); $count = $total_count ['skaits']; vai vienkāršāk: $q = mysql_query('select count(*) from jaunumi'; list($count) = mysql_fetch_row($q); Link to comment Share on other sites More sharing options...
johanes Posted June 23, 2005 Author Report Share Posted June 23, 2005 Liels paldies :) Prieciigus ligo sveetkus.... :D :D :D Link to comment Share on other sites More sharing options...
johanes Posted June 23, 2005 Author Report Share Posted June 23, 2005 Īstenībā kļūdu rada šeit $row_date = htmlspecialchars(mysql_result($result, $i, "date")); $row_message = htmlspecialchars(mysql_result($result, $i, "message")); Link to comment Share on other sites More sharing options...
v3rb0 Posted June 23, 2005 Report Share Posted June 23, 2005 WHERE 1 nozīmē to pašu, ko WHERE True, vai WHERE 1=1. Tb visas rindas (jēga gan nekāda), laikam pielietojums where true ir tikai tad kad generee visu where dalju un esi par slinku noskaidrot vai where vispar ir, tad raksti $sql .= 'where true ' if (kaut kas) { $sql .= ' and shis= tas '; } if (kaut kas cits) { $sql .= ' and tas=shis '; } citus gadiijumus kaut kaa nevaru iedomaaties:) Link to comment Share on other sites More sharing options...
bubu Posted June 23, 2005 Report Share Posted June 23, 2005 Nez, es labāk šādi tad daru: $where = array(); if ($kautkas) { $where[] = "abc = xxx"; } if ($citskautkas) { $where[] = "cits = 4"; } if ($where) { // pēc Venom metodes :) $sql .= 'WHERE ' . implode(' AND ', $where); } Citās valodās tas noteikti ir efektīvāk, jo stringus konkatenēt ir lēnāk, nekā masīvam pievienot elementu. Par php nezinu, neesmu testējis, pārsvārā šādu metodi izmanotju JavaScript kodā :) Link to comment Share on other sites More sharing options...
Recommended Posts