Showing data from category with php mysql - php

My tables are:
barangtbl: id, judul_barang, judul_seo, keywords, deskripsi, id_kat, id_sub, id_supersub, kategori_seo, view, gambar
kategori: id_kat, nama_kat
subkategori: id_sub, id_kat, nama_sub
supersubkategori: id_supersub, id_sub, id_kat, nama_supersub
I have a problem with showing data in category from database with PHP, the problem is when i click link: localhost/test/category.php?name=HPI, it doesn't show any data, but if I change HPI with number: 15, it show all.
15 is id_supersub data on supersubkategori table where I join with barangtbl table. So, all i want is if someone click: localhost/test/category.php?name=HPI it will show data with HPI category inside. How solve this problem?
<?php
if (isset($_GET['name']))
{
$kategori = $_GET['name'];
}
include "config.php";
if ((isset($kategori)) =='')
{
$query = "SELECT * FROM barangtbl INNER JOIN supersubkategori on supersubkategori.id_supersub = barangtbl.id_supersub ORDER BY id DESC LIMIT 0,12";
$hasil = mysql_query($query);
$numrows = mysql_num_rows($hasil);
}
else
{
echo "
<table width=\"100%\">
<tr>
<td align=\"center\"><b><font color=\"red\" size=\"2.5\">[ ".$_GET['name']." ]</b></font></td>
</tr>
</table>";
$query = "SELECT * FROM barangtbl WHERE id_supersub = '$kategori' ORDER BY id";
$hasil = mysql_query($query);
$numrows = mysql_num_rows($hasil);
}
?>
<table cellpadding="10" cellspacing="2" align="center">
<tr>
<?php
$kolom=3;
$x = 0;
if($numrows > 0)
{
while($data=mysql_fetch_array($hasil))
{
if ($x >= $kolom)
{
echo "</tr><tr>";
$x = 0;
}
$x++;
?>
<th>
<div id="title">
<a href="product.php?id=<?php echo $data['id']; ?>">
<?php echo $data['judul_barang']; ?>
</a>
<br><br>
</div>
<div id="image">
<a href="product.php?id=<?php echo $data['id']; ?>">
<img width='150' height='150' valign='top' border='1,5' src="product/<?php echo $data['gambar']; ?>" />
</a>
<br><br>
</div>
<div id="action">
<?php
echo '
<a href="product.php?id='.$data['id'].'">
<img src="images/detail.jpg"\ title="Detail Barang" border="0" width=\"50\" height=\"30\">
</a>';
?>
</div>
<hr />
</th>
<?php
}
}
?>
</tr>
</table>

Try removing the quotes
$query = "SELECT * FROM barangtbl WHERE id_supersub = $kategori ORDER BY id";

Related

php/html table structure not working as I want it to

I'm trying to make a table of which it is pulling information from a database. Its suppose to list the module name and then how many assignments are in it. There are two database tables involved, one simply is an id and modulename, other is id, assignment, topic, content, etc. For some reason my table won't appear correctly, it just continues rather than starting on a new line for that table. here's a picture of what it is doing
enter image description here
here's the code(if more is needed let me know):
<div id="module_1" class="row CourseModule">
<a href="#" onclick="showAssignments(1);">
<div class="col-lg-12 columnPad">
<h1-1 class="lead">List of Modules</h1-1>
</a>
<div class="pullright">
<a id="addAssignmentbutton_1" class="btn btn-primary ThemeButton" href="#" onclick="addAssignment(1);"> Add Assignment</a>
</div>
</div>
</div>
<div id="module_Assignments_1" class="row CanvasPad" style="display:none;">
<table class="CanvasTable">
<thead>
<th>
Module
</th>
<th>
Assignments
</th>
</thead>
<?php
while($row = mysqli_fetch_assoc($result)){
$count = 0;
$query = "SELECT module_id FROM module_records";
$result2 = mysqli_query($con, $query);
if(!$result2){
echo "Can't retrieve data " . mysqli_error($con);
exit;
}
while ($modInassignment = mysqli_fetch_assoc($result2)){
if($modInassignment['module_id'] == $row['module_id']){
$count++;
}
}
?>
<td>
<?php echo $row['module_name']; ?>
</td>
<td>
<span class="badge"><?php echo $count; ?></span>
</td>
<?php } ?>
List all assignments
</table>
</div>
.js
function showAssignments(module_id){
var html_id = "#module_Assignments_" + module_id;
if($(html_id).css("display") == 'block'){
$(html_id).css("display", "none");
} else {
$(html_id).css("display", "block");
}
}
You need a table row tr and then the table data td in it
Also, not required but good for grouping without adding divs/class/id; add all these tr inside a tbody if needed. Read more why it's not required here
<table class="CanvasTable">
<thead>
<th>
Module
</th>
<th>
Assignments
</th>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_assoc($result)){
$count = 0;
$query = "SELECT module_id FROM module_records";
$result2 = mysqli_query($con, $query);
if(!$result2){
echo "Can't retrieve data " . mysqli_error($con);
exit;
}
while ($modInassignment = mysqli_fetch_assoc($result2)){
if($modInassignment['module_id'] == $row['module_id']){
$count++;
}
}
?>
<tr>
<td>
<?php echo $row['module_name']; ?>
</td>
<td>
<span class="badge"><?php echo $count; ?></span>
</td>
</tr>
<?php } ?>
</tbody>
List all assignments
</table>
More info: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr

Will a LIKE function give me better results when Match Against function does not give any results in Mysql

Currently, When I type 'M' in the search engine I do not get any results inspite of having a 'Math' value in my database. (I am using Match Against function of mysql on my website). So I decided to make a code that first runs a Match Against function and if no output is obtained, it again runs the search but this time using 'LIKE' function of my sql and if still no result is obtained it shows alert 'no values found'.
the gist of code is somewhat like this..
mysql(Match against function)
If (mysqli_num_rows > 0)
{output}
elseif (mysqli_num_rows < 1)
{ mysqli (LIKE function)
then show output}
else {show alert'no results'}
Will this code give the result 'Math' when I enter 'M' in the search engine.
The actual code.
<?php
if (isset($_POST['go']))
{ $search = $_POST['search'];
$college = $_POST['colleges'];
if (!empty($search))
{
if(isset($_POST['colleges']) )
{
$query1 = "Select filename, description, groupid, emailid, college, upload_date FROM images WHERE MATCH(description) AGAINST('$search') AND college = '$college' group by groupid order by MATCH(description) AGAINST('$search') DESC";
$query_run1 = mysqli_query($con, $query1) ;
}
else
{
$query1 = "Select filename, description, groupid, emailid, college,upload_date FROM images WHERE MATCH(description) AGAINST('$search') group by groupid order by MATCH(description) AGAINST('$search') DESC";
$query_run1 = mysqli_query($con, $query1) ;
$searchresults = mysqli_num_rows($query_run1);
?><p class = "totalresults"> <br />
<br /> &nbsp &nbsp <font size= "4" >Total Results :
<?php
echo $searchresults ;
?>
</font> </p>
<?php
if(mysqli_num_rows($query_run1)>0)
{
?>
<table class="searchenginelist" style="color: black;">
<tr>
<th> Uploader </th>
<th> Title </th>
<th> Date </th>
<th> Upvotes </th>
<th> Downvotes </th>
<th> College </th>
</tr>
<?php
while( $rows = mysqli_fetch_assoc($query_run1))
{
//$imagedisplay = $rows['file'];
$imagename = $rows['filename'];
// mysqli_real_escape_string($con,$imagedisplay);
$descrip = $rows['description'];
$groupid = $rows['groupid'];
//$groupid = $_SESSION['groupid'] ;
$uploader_emailid = $rows['emailid'];
$college = $rows['college'];
?>
<tr>
<td width="70px"> <?php
$query = " SELECT username from userinfo WHERE emailid = '$uploader_emailid' " ;
$query_run = mysqli_query($con,$query );
$raw = mysqli_fetch_assoc($query_run);
echo $raw['username']; ?>
</td>
<td width="450px"> <a href="imagespace.php?groupid=<?php echo $groupid ;?>">
<?php echo $descrip ; ?>
</a>
</td>
<td style="font-size:15px;" width="85px">
<?php echo $rows['upload_date'] ; ?>
</td>
<td align="center" style="color:green;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '1' ";
$query_run= mysqli_query($con, $query);
$upvote=mysqli_num_rows($query_run) ;
echo $upvote;
?>
</td>
<td align="center" style="color:red;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '0' ";
$query_run= mysqli_query($con, $query);
$downvote=mysqli_num_rows($query_run) ;
echo $downvote;
?>
</td>
<td style="font-size:13px;" width="130px">
<?php echo $college; ?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
elseif(mysqli_num_rows($query_run1) < 1)
{
$query12 = "Select * FROM images WHERE description LIKE '%".mysqli_real_escape_string($con,$search)."%' group by groupid order by groupid DESC";
$query_run12 = mysqli_query($con, $query12) ;
?> <table class="searchenginelist" style="color: black;">
<tr>
<th> Uploader </th>
<th> Title </th>
<th> Date </th>
<th> Upvotes </th>
<th> Downvotes </th>
<th> College </th>
</tr>
<?php
while( $rows = mysqli_fetch_assoc($query_run12))
{
//$imagedisplay = $rows['file'];
$imagename = $rows['filename'];
// mysqli_real_escape_string($con,$imagedisplay);
$descrip = $rows['description'];
$groupid = $rows['groupid'];
//$groupid = $_SESSION['groupid'] ;
$uploader_emailid = $rows['emailid'];
$college = $rows['college'];
?>
<tr>
<td width="70px"> <?php
$query = " SELECT username from userinfo WHERE emailid = '$uploader_emailid' " ;
$query_run = mysqli_query($con,$query );
$raw = mysqli_fetch_assoc($query_run);
echo $raw['username']; ?>
</td>
<td width="450px"> <a href="imagespace.php?groupid=<?php echo $groupid ;?>">
<?php echo $descrip ; ?>
</a>
</td>
<td style="font-size:15px;" width="85px">
<?php echo $rows['upload_date'] ; ?>
</td>
<td align="center" style="color:green;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '1' ";
$query_run= mysqli_query($con, $query);
$upvote=mysqli_num_rows($query_run) ;
echo $upvote;
?>
</td>
<td align="center" style="color:red;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '0' ";
$query_run= mysqli_query($con, $query);
$downvote=mysqli_num_rows($query_run) ;
echo $downvote;
?>
</td>
<td style="font-size:13px;" width="130px">
<?php echo $college; ?>
</td>
</tr>
}
?>
</table>
<?php
}
else
{
echo '<script type="text/javascript"> alert ("No results found") </script>' ;
}
}
else
{ echo '<script type="text/javascript"> alert ("No data entered") </script>';
}
}
}
You have some syntax issues in your code, your else statements were not lined up properly, so your page was not working. (For example, you had an } else { lined up with another } else {).
I went through all of the code and formatted it so I could see what the issue was, remember, Some sensible code indentation would be a good idea.
It helps us read the code and more importantly it will help you debug your code.
Take a quick look at a coding standard for your own benefit.
You may be asked to amend this code in a few weeks/months and you will thank me in the end.
<?php
if (isset($_POST['go'])) {
$search = $_POST['search'];
$college = $_POST['colleges'];
if (!empty($search)) {
if(isset($_POST['colleges']) ) {
$query1 = "Select filename, description, groupid, emailid, college, upload_date FROM images WHERE MATCH(description) AGAINST('$search') AND college = '$college' group by groupid order by MATCH(description) AGAINST('$search') DESC";
$query_run1 = mysqli_query($con, $query1);
} else {
$query1 = "Select filename, description, groupid, emailid, college,upload_date FROM images WHERE MATCH(description) AGAINST('$search') group by groupid order by MATCH(description) AGAINST('$search') DESC";
$query_run1 = mysqli_query($con, $query1);
$searchresults = mysqli_num_rows($query_run1);
?>
<p class = "totalresults">
<br />
<br />
&nbsp &nbsp <font size= "4" >Total Results: <?php echo $searchresults; ?></font>
</p>
<?php
if(mysqli_num_rows($query_run1)>0) {
?>
<table class="searchenginelist" style="color: black;">
<tr>
<th> Uploader </th>
<th> Title </th>
<th> Date </th>
<th> Upvotes </th>
<th> Downvotes </th>
<th> College </th>
</tr>
<?php
while( $rows = mysqli_fetch_assoc($query_run1)) {
//$imagedisplay = $rows['file'];
$imagename = $rows['filename'];
// mysqli_real_escape_string($con,$imagedisplay);
$descrip = $rows['description'];
$groupid = $rows['groupid'];
//$groupid = $_SESSION['groupid'] ;
$uploader_emailid = $rows['emailid'];
$college = $rows['college'];
?>
<tr>
<td width="70px">
<?php
$query = " SELECT username from userinfo WHERE emailid = '$uploader_emailid' " ;
$query_run = mysqli_query($con,$query );
$raw = mysqli_fetch_assoc($query_run);
echo $raw['username'];
?>
</td>
<td width="450px">
<a href="imagespace.php?groupid=<?php echo $groupid ;?>">
<?php
echo $descrip;
?>
</a>
</td>
<td style="font-size:15px;" width="85px">
<?php
echo $rows['upload_date'] ;
?>
</td>
<td align="center" style="color:green;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '1' ";
$query_run= mysqli_query($con, $query);
$upvote=mysqli_num_rows($query_run) ;
echo $upvote;
?>
</td>
<td align="center" style="color:red;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '0' ";
$query_run= mysqli_query($con, $query);
$downvote=mysqli_num_rows($query_run) ;
echo $downvote;
?>
</td>
<td style="font-size:13px;" width="130px">
<?php
echo $college;
?>
</td>
</tr>
<?php
} //end while loop
?>
</table>
<?php
} else if(mysqli_num_rows($query_run1) < 1) {
$query12 = "Select * FROM images WHERE description LIKE '%".mysqli_real_escape_string($con,$search)."%' group by groupid order by groupid DESC";
$query_run12 = mysqli_query($con, $query12) ;
?>
<table class="searchenginelist" style="color: black;">
<tr>
<th> Uploader </th>
<th> Title </th>
<th> Date </th>
<th> Upvotes </th>
<th> Downvotes </th>
<th> College </th>
</tr>
<?php
while( $rows = mysqli_fetch_assoc($query_run12)) {
//$imagedisplay = $rows['file'];
$imagename = $rows['filename'];
// mysqli_real_escape_string($con,$imagedisplay);
$descrip = $rows['description'];
$groupid = $rows['groupid'];
//$groupid = $_SESSION['groupid'] ;
$uploader_emailid = $rows['emailid'];
$college = $rows['college'];
?>
<tr>
<td width="70px">
<?php
$query = " SELECT username from userinfo WHERE emailid = '$uploader_emailid' " ;
$query_run = mysqli_query($con,$query );
$raw = mysqli_fetch_assoc($query_run);
echo $raw['username'];
?>
</td>
<td width="450px">
<a href="imagespace.php?groupid=<?php echo $groupid ;?>">
<?php
echo $descrip ;
?>
</a>
</td>
<td style="font-size:15px;" width="85px">
<?php
echo $rows['upload_date'] ;
?>
</td>
<td align="center" style="color:green;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '1' ";
$query_run= mysqli_query($con, $query);
$upvote=mysqli_num_rows($query_run) ;
echo $upvote;
?>
</td>
<td align="center" style="color:red;" width="50px">
<?php
$query = "SELECT vote from votes where groupid = '$groupid' and vote = '0' ";
$query_run= mysqli_query($con, $query);
$downvote=mysqli_num_rows($query_run) ;
echo $downvote;
?>
</td>
<td style="font-size:13px;" width="130px">
<?php
echo $college;
?>
</td>
</tr>
</table>
<?php
} //end while loop
} else { //num rows < 1
echo '<script type="text/javascript"> alert ("No results found") </script>' ;
}
}
} else { //no searches returned
echo '<script type="text/javascript"> alert ("No data entered") </script>';
}
}
I also suggest, for really complex, nested structures, to comment what each ending bracket goes to like I did in your code. I put comments so that I could see exactly what the } was ending.
WARNING: This code may be vulnerable to SQL Injection Attacks. You should Learn about Prepared Statements for MySQLi or PDO. I recommend PDO, which I wrote a function for to make it extremely easy, very clean, and way more secure than using non-parameterized queries.
If you could access the mysql.ini of your host, you could simply change the min word length for full text search.
[mysqld]
ft_min_word_len=N
Otherwise you should decide which search function you want to use. It's not very intuitive for users if one search is a full text search and the other is a simple LIKE.
One way around could also be to only use full text, if the user types more than 2 chars.
// ...
if (strlen($query) < 4) {
$where = "MATCH (...) AGAINST ...";
} else {
$where = "...LIKE ... ";
}
$sql .= $where;
Btw. MATCH AGAINST should normaly return way more results than like, so doing a LIKE search after MATCH AGAINST returns 0 rows, is kinda useless.

Custom Pagination Not Working Well in Wordpress

Im just New in Wordpress and in PHP .. Now Ive just uploaded a theme in Wordpress. The Problem is The Custom Pagination is not working in Wordpress but works well in USBWebserver. It Only Just show the Same Content
<table id="maincon2-Article">
<?php
$page2 = $_GET["page2"];
if($page2 == "" || $page2 == "1"){
$pages = 0;
}
else{
$pages = ($page2*3)-3;
}
$Mobartsql = "Select * from tbl_article ORDER BY `Article_ID` DESC limit 1,3";
$result4 = $con->query($Mobartsql);
while($row4 = $result4->fetch_assoc()){
echo '<tr>
<td style="width:50%">
<img src = "https://www.stlouisreviewcenter.com/wp-content/uploads/slrc/'.$row4["Art_pic"].'" id="artpiclink2"/>
</td>
<td style="padding-left:2%" >
<h1 id="art-head2" style="color:purple">'.$row4["Art_title"].' </h5>
</td>
</tr>';
$results1 = $con->query("Select * from tbl_article ORDER BY `Article_ID` DESC");
$rows2 = $result1->num_rows/3;
$rows2 = ceil($rows2);
}
echo '<tr>
<td><br></td>
</tr>
<tr>
<td colspan="2">';
for($i=1; $i<=$rows;$i++){
?> <button> <a href="/article/?page=<?php echo $i;?>" style="text-decoration:none;"/><?php echo $i; ?></a> </button>
<?php
}
?>
</td>
</tr>
<tr>
<td><br/></td>
</tr>
</table>
Here is the Sample .. Plz Need Help ..

Automatically make new box by reading from database

I've got a box with information that I read from database(news) , but I've got another database(categories) with the category of that box. If the categories are 7 I want to automatically make 7 box.
<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("tnews2") or die(mysql_error());
mysql_query("set names 'utf8'");
$rowsPerPage = 2;
$query1 = "SELECT id,name FROM categories ORDER BY ID";
$result1 = mysql_query($query1) or die(mysql_error()."[".$query1."]");
$query2 = "SELECT id,name,text,img,cat_id FROM news WHERE cat_id=2 ORDER BY ID DESC LIMIT $rowsPerPage";
$result2 = mysql_query($query2) or die(mysql_error()."[".$query2."]");
?>
while($row = mysql_fetch_array($result1)){ ?>
<?php for($i=0; $i<$row['id']; $i++){ ?>
<div class="focusBussines" >
<?php while ($rowB = mysql_fetch_array($result2)){ ?>
<a class="titleMini" href="categories.php?id=<?= $rowB['id'] ?>&cat_id=<?=$rowB['cat_id']?>">Бизнес</a>
<?php } ?>
<table class="table" width="100%">
<?php while ($rowB2 = mysql_fetch_array($result2)){
if($rowB2['cat_id'] == 2){ ?>
<tr>
<td align="left" width="150" >
<img class="pic" src="<?php echo $rowB2["img"];?>" height="120" width="120">
</td>
<td align="left" colspan="100%" id="title" ><a id="Zaglavie" href="novina.php?id=<?= $rowB2['id'] ?>&cat_id=<?=$rowB2['cat_id']?>" > <?php echo $rowB2['name']; ?></a></td>
</tr>
<tr >
<td colspan="100%"><hr/> </td>
</tr>
<?php } } ?>
</table>
</div>
<?php } } ?>
but it doesn't work.
Your problem originates from those unnecessary opening/closing php statements (emphasize added):
$result2 = mysql_query($query2) or die(mysql_error()."[".$query2."]");
>>>>> ?> <<<<<
while($row = mysql_fetch_array($result1)){ >>>>> ?> <<<<<
>>>>> <?php <<<<< for($i=0; $i<$row['id']; $i++){ >>>>> ?> <<<<<
This is the same as writing
$result2 = mysql_query($query2) or die(mysql_error()."[".$query2."]");
while($row = mysql_fetch_array($result1)) {
for($i=0; $i<$row['id']; $i++){ ?>
and increases the readability and reduces possible errors due to missing open/close tags.

Join 2 tables by merk_id

I'm trying to combine to tables. I got 11 different brands and I got wheels that belong to a brand. You can select a brand by its name with an option selectbox and when submut I want alle the wheels with that brand.
This is the class I'm using:
<?php
include_once "connect.class.php";
class merken extends connect
{
private $merkenlijst;
public function getMerken($database, $id = NULL)
{
$sql = "SELECT * FROM ".$database."_merken";
if(!empty($id))
{
$sql .= " WHERE merk_code=:id";
}
else
{
$sql .= " ORDER BY merk_naam ASC";
}
try
{
$stmt = $this->db->prepare($sql);
if(!empty($id)){ $stmt->bindParam(":id", $id, PDO::PARAM_STR); }
$stmt->execute();
$this->merkenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
$stmt->closeCursor();
return $this->merkenlijst;
}
catch (Exception $e)
{
die ( $e->getMessage() );
}
}
public function __construct($dbo = NULL)
{
parent::__construct($dbo);
}
}
?>
This is how I echo the info from my database:
<div class="bandwielkolom">
<form action="index.php?lang=nl&p=<?php echo $_GET['p']; ?>#keuze" method="post">
<table class="bandentabel">
<tr>
<th colspan="2">Zoek op merk<a name="wiel"></a></th>
</tr>
<tr>
<td>Merk:</td>
<td>
<select name="wiel_merk">
<option value="0">- Merk -</option>
<?php
$merken = $merkclass->getMerken($website);
foreach($merken as $merk)
{
echo "\t\t\t\t\t\t\t\t\t\t\t<option value=\"".$merk->merk_code."\"";
if(isset($_GET['search']) && $_GET['search'] == "wiel" && isset($_GET['merk']) && $_GET['merk'] == $merk->merk_code || isset($_POST['wiel_submit']) && $_POST['wiel_merk'] == $merk->merk_code) { echo " selected=\"selected\""; }
echo ">".$merk->merk_naam."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="wiel_submit" value="Zoek" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</form>
</div>
<div class="clearboth"></div>
<br />
<?php
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == "Zoek" || isset($_GET['merk']))
{
$merk = NULL;
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == "Zoek")
{
$merk = $_POST['wiel_merk'];
}
$merken = $merkclass->getMerken($website, $merk);
foreach($merken as $merk)
{
?>
<img src="http://www.etyre.net/preview/bnet/logos/<?php echo str_replace(".png", "_150.png", $merk->merk_logo); ?>" width="150" class="logo" alt="<?php echo $merk->merk_naam; ?>"/>
<div id="merken">
<li><span class="title"><?php echo $merk->wiel_info; ?></span>
<a href="http://www.inter-tyre.nl/inter-tyre/images/w3/<?php echo $merk->wiel_foto; ?>" class="preview" title="Fotonummer: <?php echo $merk->wiel_foto; ?>">
<img src="http://www.inter-tyre.nl/inter-tyre/images/w2/<?php echo $merk->wiel_foto; ?>" alt="Fotonummer: <?php echo $merk->wiel_foto; ?>" class="wheelImg"/>
</a>
<div class="clearboth"></div>
</div>
<?php
}
?>
<?php
}
?>
How can I join this two tables together so than when I select a brand it does show all the wheels that has that brand? And no double brands in my select option?
wielen table
merken table
Can somebody help me out?
Thanks
Your question is a little unclear, and it appears to me that you are too lazy to just go and read the documentation for JOIN.
Anyway, something along the following lines should work:
SELECT w.*,m.* FROM wielen w
LEFT JOIN merken m ON w.merk_id = m.id
WHERE m.id = $your_current_merk;
This gives you a list of all wheels, together with their associated brand information.
If you want to do it the other way around and you don't want to have your brands reoccurring, with your current setup, you would want to do a GROUP_CONCAT, like in this question.

Categories