Jump to content

help begginer with php code


Myndeks

Recommended Posts

Hello,

 

$sql = "Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max";
        $for = $numRows = $conn->query("SELECT COUNT(*) FROM picture  WHERE category = 'animation'")->fetchColumn();
               
       
if ($for  > 0) {
       
               
foreach($conn->query($sql) as $row)
                {
                        print '<p>"'.$row['title'].'"</p><br><img src="'.$row['img'].'" width="651" height="215" id="img" /><br><h1><a href="'.$row['img'].'" download="'.$row['img'].'"/>Download Cover</a></h1> <hr>';
                }
               
                $conn
= null;

 

 

when i'm deleted this: 

 

 

if ($for  > 0) {
       
               
foreach($conn->query($sql) as $row)
                {
                        print '<p>"'.$row['title'].'"</p><br><img src="'.$row['img'].'" width="651" height="215" id="img" /><br><h1><a href="'.$row['img'].'" download="'.$row['img'].'"/>Download Cover</a></h1> <hr>';
                }

 

Error disappear, but code not work. And error is:

 

 

 

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' ORDER BY id DESC LIMIT -5, 5' at line 1' in D:\xamp\htdocs\uzdarbis\test.php:34 Stack trace: #0 D:\xamp\htdocs\uzdarbis\test.php(34): PDO->query('Select * from p...') #1 D:\xamp\htdocs\uzdarbis\test.php(41): covers() #2 {main} thrown in D:\xamp\htdocs\uzdarbis\test.php on line 3

 

if think what problem is here: $sql = "Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max"; but i cant uderstand where.. :/

 

if i do this; $sql = $conn->prepare("Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max"); error disapear, but code dosent work :/

Link to comment
Share on other sites

I don't understand can you help me fixed it ? :)

 

Are you asking how to fix the query? If so, jcbones already provided the corrected code. You just need to add the missing quote before animatio. Change this:

$sql = "Select * from picture WHERE category = animatio' ORDER BY id DESC LIMIT $start, $max";

To this:

$sql = "Select * from picture WHERE category = 'animatio' ORDER BY id DESC LIMIT $start, $max";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.