Jump to content
php.lv forumi

SELECT * FROM bla bla


reGative

Recommended Posts

Mans kods ir šāds:

<?php
$con = mysql_connect("serveris","username","pass");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("db", $con);

$result = mysql_query("SELECT * FROM news");

while($row = mysql_fetch_array($result))
 {
 echo $row['post-content'] . " " . $row['post-title'];
 echo "<br />";
 }
mysql_close($con);
?>

 

ok, bet pārlūkos rāda šādu tekstu:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\rG_CMS\index.php on line 12

 

Es nejēdzu, kur ir kļūda. PHP programmēšanā esmu iesācējs, pamatus zinu, vēlos iemācīties datus no datubāzes dabūt pārlūkā.

Link to comment
Share on other sites

Pameiģini šita

<?php
mysql_connect("serveris","username","pass");
mysql_select_db("db");
$select = mysql_query("SELECT * FROM news") or die(mysql_error());
while($row = mysql_fetch_array($select)){
echo $row['post-content'];
echo $row['post-title'];
}
?>

ja radis to pašu, tad tev taja dātubāzē nav tadu tabulu vai arī vispar nav tadas dātubāzes.

Link to comment
Share on other sites

Netiek pārbaudīts,vai kverijs ir veiksmīgs un vispār kaut ko atgriež.Jēdzīgāk būtu rakstīt:

if($result = mysql_query("SELECT * FROM news"))
{
if(!mysql_num_rows($result)>0)
  echo 'Ziņu nav';
else
{
 while($row = mysql_fetch_array($result))
 {
  echo $row['post-content'] . " " . $row['post-title'];
  echo "<br />";
 }
}
}
else 
 echo mysql_error();

 

Edit: iepriekšējais jau pasteidzās to pašu uzrakstīt:)

Edited by 404
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...