i need some help from you :)...when we select 'info' list in the combobox,automatically the article with type 'info' charateristic showed up, and when we select 'Berita' list in combobox,automatically the article with type 'Berita' charateristic showed up.. here is my code... it is a long script T.T & it use post method.. can you help me to make it a little bit simple? using function maybe. thanks before
<form method="post" name="form2">
<select name="type" id="type">
<option value="Semua">Semua</option>
<option value="Berita">Berita</option>
<option value="Info">Info</option>
</select>
<input type="submit" id="type" />
</form>
<table width="200" border="1" class="tbl_art_content" id="results">
<tbody>
<tr>
</tr>
<?php
$i=0;
$no=0;
if($_POST['type'] == 'Semua')
{
$query_art = mysql_query("SELECT * FROM artikel_tbl ORDER BY id") or die(mysql_error());
}
else if ($_POST['type'] == 'Berita')
{
$query_art = mysql_query("SELECT * FROM artikel_tbl WHERE type = 'Berita' ORDER BY id") or die(mysql_error());
}
else if ($_POST['type'] == 'Info')
{
$query_art = mysql_query("SELECT * FROM artikel_tbl WHERE type = 'Info' ORDER BY id") or die(mysql_error());
}
else
{
$query_art = mysql_query("SELECT * FROM artikel_tbl ORDER BY id") or die(mysql_error());
}
while($show=mysql_fetch_array($query_art))
{
$no++;
if(($no%2)==0)
$color = '#f2f2f2';
else
$color = '#f9f9f9';
?>
<tr bgcolor="<?php echo $color; ?>" class="rows">
<td class="chk_content"><input type="checkbox" name="checked<?php echo $i; ?>" value="<?php echo $show['id']; ?>"/></td>
<td class="no_content"><?php echo $no; ?></td>
<td class="middle_content"><?php echo $show['judul']; ?></td>
<td class="middle_content"><?php echo $show['penulis']; ?></td>
<td class="middle_content"><?php echo $show['type']; ?></td>
<td class="middle_content"><img src=".././upload/artikel/<?php echo $show['foto']; ?>" width="144" height="88"/></td>
<td class="middle_content"><?php echo $show['tanggal']; ?></td>
<td class="aksi_content"><div id="aksi_table">
<ul>
<li><img src="images/Apps-text-editor-icon.png" width="20" height="20" /></li>
<li><a href="table_artikel.php?delete=<?php echo $show['id']; ?>" onclick="return confirm('Hapus artikel?')";><img src="images/Remove-icon.png" width="20" height="20"/></a></li>
</ul>
</div><!-- end of aksi_table --></td>
</tr>
<?php
$i++;
}
?>
<input type="hidden" name="n" value="<?php echo $i; ?>" />
</tbody>
</table>
For starters, try this:
$type = '';
if(isset($_POST['type'])):
$type = $_POST['type'];
endif;
if($type != 'Semua'):
$query_art = mysql_query("
SELECT *
FROM artikel_tbl
WHERE type = '$type'
ORDER BY id") or die(mysql_error());
else:
$query_art = mysql_query("
SELECT *
FROM artikel_tbl
ORDER BY id") or die(mysql_error());
endif;
Related
I've never had issues programming PHP SQL updates when updating multiple rows of data with multiple columns, but for some reason this section of coding is killing me as it is nothing more than checkboxes for the end user to check and/or uncheck. I've include portions of the code below as the full code is over 50+ columns wide of checkboxes and can range from 1-200 rows.
Everything displays/runs the way its supposed to but the updating isnt functioning properly ... example: if there is 5 rows (each with a unique trackingid) and I check the checkbox for the 4th row on update it says that the 1st checkbox was checked and NOT the 4th row.
<?php if (!isset($_POST['trackingid'])) { ?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post" enctype="multipart/form-data" class="form-horizontal" id="form"><input type="hidden" name="id" value="<?php echo $id; ?>">
<table class="table table-striped">
<thead>
<tr>
<td class="rotate-alt"></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt2"><div><span></span></div></td>
<td class="rotate-alt"><div><span>Glass</span></div></td>
<td class="rotate-alt"><div><span>Glass - SDL</span></div></td>
<td class="rotate-alt"><div><span>Mill - S&R</span></div></td>
</tr>
</thead>
<tbody>
<?php $result = sqlsrv_query($conn, "SELECT id, [Order Number], [Door Number], [Qty Display], [Interior or Exterior], [Style], Species_DD_Desc, [Mill Batch Nbr],
[Glass Completed], [Glass Completed By], [Glass STD Hrs], [SDL Completed], [SDL Completed By], [SDL STD Hrs],
[Mill Completed], [Mill Completed By], [Mill STD Hrs]
FROM PD_Tracking
WHERE [Order Number] = '$id'
ORDER BY [Door Number], [Qty Display], [Mill Batch Nbr]");
$i=0;
while ($list = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){ ?>
<tr>
<td class="center">
<input type="checkbox" onclick="$('input[id=\'selid<?php echo $i; ?>\']').attr('checked', this.checked);">
<input type="hidden" name="trackingid[]" value="<?php echo $list['id']; ?>">
</td>
<td class="center"><?php echo $list['Door Number']; ?></td>
<td class="center"><?php echo $list['Qty Display']; ?></td>
<td class="center"><?php echo $list['Interior or Exterior']; ?></td>
<td class="center"><?php echo $list['Style']; ?></td>
<td class="center"><?php echo $list['Species_DD_Desc']; ?></td>
<td class="center">
<?php if (($list['Glass STD Hrs']>0) && (!isset($list['Glass Completed']))){ ?>
<input type="checkbox" name="glass[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['Glass STD Hrs']>0) && ($list['Glass Completed'] > ' ')){ ?>
<input type="checkbox" name="glass[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
<td class="center">
<?php if (($list['SDL STD Hrs']>0) && (!isset($list['SDL Completed']))){ ?>
<input type="checkbox" name="sdl[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['SDL STD Hrs']>0) && ($list['SDL Completed'] > ' ')){ ?>
<input type="checkbox" name="sdl[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
<td class="center">
<?php if (($list['Mill STD Hrs']>0) && (!isset($list['Mill Completed']))){ ?>
<input type="checkbox" name="mill[]" id="selid<?php echo $i; ?>">
<?php } else if (($list['Mill STD Hrs']>0) && ($list['Mill Completed'] > ' ')){ ?>
<input type="checkbox" name="mill[]" checked="checked" id="selid<?php echo $i; ?>">
<?php } else { ?>
NR
<?php } ?>
</td>
</tr>
<?php ++$i;
} ?>
</tbody>
</table>
<?php } // END if (!isset($_POST['trackingid'])) {
if (isset($_POST['trackingid'])) {
$query = sqlsrv_query($conn, "SELECT * FROM users WHERE id=".$_SESSION['auid']."");
$row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);
$employee_num = $row['Employee Number'];
$size = count($_POST['trackingid']);
for($i=0; $i < $size; $i++){
$trackingid = $_POST['trackingid'][$i];
$query = "UPDATE PD_Tracking SET ";
if(isset($_POST['glass'][$i])){
$query .= "[Glass Completed]='$date_time_entered', [Glass Completed By]='$employee_num', ";
} else {
$query .= "[Glass Completed]= NULL, [Glass Completed By]= NULL, ";
}
if(isset($_POST['sdl'][$i])){
$query .= "[SDL Completed]='$date_time_entered', [SDL Completed By]='$employee_num', ";
} else {
$query .= "[SDL Completed]= NULL, [SDL Completed By]= NULL, ";
}
if(isset($_POST['mill'][$i])){
$query .= "[Mill Completed]='$date_time_entered', [Mill Completed By]='$employee_num' ";
} else {
$query .= "[Mill Completed]= NULL, [Mill Completed By]= NULL ";
}
$query .= "WHERE id='$trackingid'";
$query = sqlsrv_query($conn, $query);
} // END for($i=0; $i < $size; $i++){?>
<SCRIPT LANGUAGE='JavaScript'>
<!-- Begin
window.location = '<?php echo $_SERVER['REQUEST_URI']; ?>&success=edit';
// End -->
</script>
<?php } // END if (isset($_POST['trackingid'])) { ?>
My purpose is search book type from input keyboard and count it. I have error: counting the number of book is right but when print, it miss some result. For example, I put 'f' it show 7 result( right) however it print only 2 two result. Here is my code:
<form action="" method="POST">
Enter type of book here:<input type="text" size="20" name="sbt"> <br />
<input type="submit" name="sb" value="Search">
</form>
<table align="center" border="1" width="600">
<thead><tr align="center">
<tr align="center">
<td><b>Book ID</b></td>
<td><b>Book Title</b></td>
<td><b>Book Author</b></td>
<td><b>Pulished Year</b></td>
<td><b>Book Type</b></td>
<td><b>Status</b></td>
</tr>
<?php
if (isset($_POST['sb'])) {
$s="";
if ($_POST['sbt'] == null) {
echo "Please re-enter <br>";
} else
{
$s = $_POST['sbt'];
}
$q = "SELECT * FROM book WHERE book_type LIKE '%$s%' ";
$r= mysqli_query($conn,$q);
while($row = mysqli_fetch_array($r)) {
?>
<tr align="center">
<td><?php echo $row['book_no'];?></td>
<td><?php echo $row['book_title'];?></td>
<td><?php echo $row['book_author'];?></td>
<td><?php echo $row['book_year'];?></td>
<td><?php echo $row['book_type'];?></td>
<td>
<?php
if ($row['book_quantity'] == 1) {
echo "Available";
}
else {
echo "Not available";
}
?>
</td>
<?php
$c=" SELECT COUNT(DISTINCT(book_no)) AS totaltype FROM book WHERE book_type LIKE '%$s%'";
$s= mysqli_query($conn, $c);
if (mysqli_num_rows($s)> 0 )
{
$row2= mysqli_fetch_array($s);
echo " Total book type result:"."{$row2['totaltype']}";
}
}
?>
<?php } ?>
</table>
Remove "%" before $s and try.
for example:
$query = mysql_query("SELECT * FROM table WHERE the_number LIKE '$yourPHPVAR%'");
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";
I am trying to do two things one is to Sort By Date last created the next one is to limit the the amount of data show to five (5) so ticket one, ticket two, ticket three, four, and five
I am making a drop down window that shows the last 5 ticket that was created and i am getting the information from below
Thank you for your help
<?php
if(!defined('OSTCLIENTINC') || !is_object($thisclient) || !$thisclient->isValid()) die('Access Denied');
$qstr='&'; //Query string collector
$status=null;
if(isset($_REQUEST['status'])) { //Query string status has nothing to do with the real status used below.
$qstr.='status='.urlencode($_REQUEST['status']);
//Status we are actually going to use on the query...making sure it is clean!
switch(strtolower($_REQUEST['status'])) {
case 'open':
case 'closed':
$status=strtolower($_REQUEST['status']);
break;
default:
$status=''; //ignore
}
} elseif($thisclient->getNumOpenTickets()) {
$status='open'; //Defaulting to open
}
$sortOptions=array('id'=>'`number`', 'subject'=>'subject.value',
'status'=>'ticket.status', 'dept'=>'dept_name','date'=>'ticket.created');
$orderWays=array('DESC'=>'DESC','ASC'=>'ASC');
//Sorting options...
$order_by=$order=null;
$sort=($_REQUEST['sort'] && $sortOptions[strtolower($_REQUEST['sort'])])?strtolower($_REQUEST['sort']):'date';
if($sort && $sortOptions[$sort])
$order_by =$sortOptions[$sort];
$order_by=$order_by?$order_by:'ticket_created';
if($_REQUEST['order'] && $orderWays[strtoupper($_REQUEST['order'])])
$order=$orderWays[strtoupper($_REQUEST['order'])];
$order=$order?$order:'ASC';
if($order_by && strpos($order_by,','))
$order_by=str_replace(','," $order,",$order_by);
$x=$sort.'_sort';
$$x=' class="'.strtolower($order).'" ';
$qselect='SELECT ticket.ticket_id,ticket.`number`,ticket.dept_id,isanswered, '
.'dept.ispublic, subject.value as subject,'
.'dept_name,ticket. status, ticket.source, ticket.created ';
$dynfields='(SELECT entry.object_id, value FROM '.FORM_ANSWER_TABLE.' ans '.
'LEFT JOIN '.FORM_ENTRY_TABLE.' entry ON entry.id=ans.entry_id '.
'LEFT JOIN '.FORM_FIELD_TABLE.' field ON field.id=ans.field_id '.
'WHERE field.name = "%1$s" AND entry.object_type="T")';
$subject_sql = sprintf($dynfields, 'subject');
$qfrom='FROM '.TICKET_TABLE.' ticket '
.' LEFT JOIN '.DEPT_TABLE.' dept ON (ticket.dept_id=dept.dept_id) '
.' LEFT JOIN '.TICKET_COLLABORATOR_TABLE.' collab
ON (collab.ticket_id = ticket.ticket_id
AND collab.user_id ='.$thisclient->getId().' )'
.' LEFT JOIN '.$subject_sql.' subject ON ticket.ticket_id = subject.object_id ';
$qwhere = sprintf(' WHERE ( ticket.user_id=%d OR collab.user_id=%d )',
$thisclient->getId(), $thisclient->getId());
if($status){
$qwhere.=' AND ticket.status='.db_input($status);
}
$search=($_REQUEST['a']=='search' && $_REQUEST['q']);
if($search) {
$qstr.='&a='.urlencode($_REQUEST['a']).'&q='.urlencode($_REQUEST['q']);
if(is_numeric($_REQUEST['q'])) {
$qwhere.=" AND ticket.`number` LIKE '$queryterm%'";
} else {//Deep search!
$queryterm=db_real_escape($_REQUEST['q'],false); //escape the term ONLY...no quotes.
$qwhere.=' AND ( '
." subject.value LIKE '%$queryterm%'"
." OR thread.body LIKE '%$queryterm%'"
.' ) ';
$deep_search=true;
//Joins needed for search
$qfrom.=' LEFT JOIN '.TICKET_THREAD_TABLE.' thread ON ('
.'ticket.ticket_id=thread.ticket_id AND thread.thread_type IN ("M","R"))';
}
}
$total=db_count('SELECT count(DISTINCT ticket.ticket_id) '.$qfrom.' '.$qwhere);
$page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav=new Pagenate($total, $page, PAGE_LIMIT);
$pageNav->setURL('tickets.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&order='.urlencode($_REQUEST['order']));
//more stuff...
$qselect.=' ,count(attach_id) as attachments ';
$qfrom.=' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON ticket.ticket_id=attach.ticket_id ';
$qgroup=' GROUP BY ticket.ticket_id';
$query="$qselect $qfrom $qwhere $qgroup ORDER BY $order_by $order LIMIT ".$pageNav->getStart().",".$pageNav->getLimit();
//echo $query;
$res = db_query($query);
$showing=($res && db_num_rows($res))?$pageNav->showing():"";
$showing.=($status)?(' '.ucfirst($status).' Tickets'):' All Tickets';
if($search)
$showing="Search Results: $showing";
$negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting
?>
<h1>Tickets</h1>
<br>
<form action="tickets.php" method="get" id="ticketSearchForm">
<input type="hidden" name="a" value="search">
<input type="text" name="q" size="20" value="<?php echo Format::htmlchars($_REQUEST['q']); ?>">
<select name="status">
<option value="">— Any Status —</option>
<option value="open"
<?php echo ($status=='open')?'selected="selected"':'';?>>Open (<?php echo $thisclient->getNumOpenTickets(); ?>)</option>
<?php
if($thisclient->getNumClosedTickets()) {
?>
<option value="closed"
<?php echo ($status=='closed')?'selected="selected"':'';?>>Closed (<?php echo $thisclient->getNumClosedTickets(); ?>)</option>
<?php
} ?>
</select>
<input type="submit" value="Go">
</form>
<a class="refresh" href="<?php echo Format::htmlchars($_SERVER['REQUEST_URI']); ?>">Refresh</a>
<table id="ticketTable" width="800" border="0" cellspacing="0" cellpadding="0">
<caption><?php echo $showing; ?></caption>
<thead>
<tr>
<th width="70" nowrap>
Ticket #
</th>
<th width="100">
Create Date
</th>
<th width="80">
Status
</th>
<th width="300">
Subject
</th>
<th width="150">
Department
</th>
<th width="100">Phone Number</th>
</tr>
</thead>
<tbody>
<?php
if($res && ($num=db_num_rows($res))) {
$defaultDept=Dept::getDefaultDeptName(); //Default public dept.
while ($row = db_fetch_array($res)) {
$dept=$row['ispublic']?$row['dept_name']:$defaultDept;
$subject=Format::htmlchars(Format::truncate($row['subject'],40));
if($row['attachments'])
$subject.=' <span class="Icon file"></span>';
$ticketNumber=$row['number'];
if($row['isanswered'] && !strcasecmp($row['status'],'open')) {
$subject="<b>$subject</b>";
$ticketNumber="<b>$ticketNumber</b>";
}
$phone=Format::phone($row['phone']);
if($row['phone_ext'])
$phone.=' '.$row['phone_ext'];
?>
<tr id="<?php echo $row['ticket_id']; ?>">
<td class="centered">
<a class="Icon <?php echo strtolower($row['source']); ?>Ticket" title="<?php echo $row['email']; ?>"
href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $ticketNumber; ?></a>
</td>
<td> <?php echo Format::db_date($row['created']); ?></td>
<td> <?php echo ucfirst($row['status']); ?></td>
<td>
<?php echo $subject; ?>
</td>
<td> <?php echo Format::truncate($dept,30); ?></td>
<td><?php echo $phone; ?></td>
</tr>
<?php
}
} else {
echo '<tr><td colspan="7">Your query did not match any records</td></tr>';
}
?>
</tbody>
</table>
<?php
if($res && $num>0) {
echo '<div> Page:'.$pageNav->getPageLinks().' </div>';
}
?>
$limit='';
$i=0;
$q=mysql_query(...)
while($i<=mysql_num_rows($q))
{
$b=$i+5;
$limit='limit '.$i.', '.$b;
mysql_query(...$limit)
}
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.