Jump to content

Recommended Posts

Hi Everyone, hope everyone had a great weekend. I'm new to php and SQL and have been learning on the side. I've created a simple SQL DB to just learn with. I'm sure this is a simple answer just not knowledgable enough yet and unsure where to look.

 

Here's where my test MySQL/PHP page is located at. It's a very simple database table:

http://www.capellnet.com/SQL/cars.php

 

As you can see I created a field that lists the vehicle types. Is there a way to only pass the values of the "trucks" for example or the "cars" that way it only displays the vehicles that are that type in the list.

 

I would assume in this test it would be a "select" statement of some type? Here's what inside the PHP file so far. Thanks again for any help provided.

 

Newbie in training :-)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SQL Cars Example</title>
</head>
<link rel="stylesheet" type="text/css" href="../styles/main.css" />
<body>
<div id="wrapper">
<div id="header"></div>
    <div id="fullcolumn">
    <h2>Photos of cars</h2>
    
<?php
include '';
include '';

$sql='SELECT * FROM images';
$result=mysql_query($sql) or die(mysql_error());
$numRows=mysql_num_rows($result);
?> 

<p>A total of <?php echo $numRows; ?> records were found.</p>

<table>
    	<tr>
        	<th>image_id</th>
            <th>filename</th>
            <th>type</th>
	</tr>
    <?php
while ($row=mysql_fetch_assoc ($result)) {
   ?>
   	<tr>
    	<td><?php echo $row ['image_id']; ?></td>
        <td><img src="images/<?php echo $row ['filename']; ?>" /><br />
        <?php echo $row ['caption']; ?></td>
        <td><?php echo $row ['type']; ?></td>
    </tr>
    <?php } ?>
    </table>
        
    </div>    
    <div id="footer"></div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/163191-mysql-statements-help/
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.