Forum Moderators: coopster

Message Too Old, No Replies

PHP accessing arrays and display results

         

pixeldiver

1:46 am on Jun 27, 2009 (gmt 0)

10+ Year Member



Hi PHP Gurus

I posted this a couple days ago:

I'm trying to develop a graphical user interface using a form. The interface consists of two selection groups with images.

Selection group 1: Application; a user has different options to select from Commercial, Health etc. (one only).

Selection group 2: Installation; same again a user can select from different options: Pendant, Recessed etc. (one only).

And there is a submit button where users can submit their search.
I should be able to display images retrieved from mysql depending on choices beeing made.

The database consists of images with corresponding rows like pendant commercial all with a value of 1 or 0.

Here is what I got so far:

<?php require_once('Connections/qmi.php'); ?>
<?php

$a = $_POST['application'];
foreach ( $a as $application )
{ }
$i = $_POST['installation'];
foreach ( $i as $installation )
{ }

mysql_select_db($database_qmi, $qmi);
$query = "SELECT img_link_beam, img_link_tubular, img_link_symmetric, img_link_asymmetric, img_link_modular FROM searchmatrix WHERE application_type LIKE'%{$a}%' AND installation_type LIKE'%{$POST['installation']}%'";
$result = mysql_query($query, $qmi) or die(mysql_error());
$row = mysql_fetch_array($result);
$totalRows = mysql_num_rows($result);

<body>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="do" value="this" />
<label>
<input type="radio" name="application[]" value="commercial" />
Commercial</label>
<label>
<input type="radio" name="application[]" value="education" />
Education</label>
<label>
<input type="radio" name="application[]" value="health" />
Health</label>
<input type="radio" name="application[]" value="industrial" />
Industrial</label>

<input type="radio" name="installation[]" value="pendant" />
Pendant</label>
<label>
<input type="radio" name="installation[]" value="wallmount" />
Wall Mount</label>
<label>
<input type="radio" name="installation[]" value="recessed" />
Recessed</label>
<label>
<input type="radio" name="installation[]" value="floormount" />
Floor Mount </label>
<br />
<br />
SEARCH
<input type="submit" name="submit" id="submit" value="Submit" />
<br />
</p>

</form>
Selected Application: <?php echo "$application"; ?><br />
Selected Installation: <?php echo "$installation"; ?>

<?php do { ?>
<div id="results"><?php echo $row ['img_link_beam']; ?> &nbsp;<?php echo $row ['img_link_tubular']; ?><?php echo $row ['img_link_symmetric']; ?><?php echo $row ['img_link_asymmetric']; ?><?php echo $row ['img_link_modular']; ?></div>
<?php } while ($row = mysql_fetch_array($result)); ?>
</body>
</html>
<?php
mysql_free_result($result);
?>

There is something wrong with my arrays, and I dont get any results from DB.
Would appreciate any suggestions (I am not the youngest to start with PHP).

Cheers

bkeep

4:10 pm on Jun 27, 2009 (gmt 0)

10+ Year Member



If I read what you want to do in your first sentence you are not needing to send your radio button info via an array
This should work fine, since you only are allowing one selection.

<input type="radio" name="application" value="commercial" />
Commercial</label>
<label>
<input type="radio" name="application" value="education" />
Education</label>
<label>
<input type="radio" name="application" value="health" />
Health</label>
<input type="radio" name="application" value="industrial" />
Industrial</label>

<input type="radio" name="installation" value="pendant" />
Pendant</label>
<label>
<input type="radio" name="installation" value="wallmount" />
Wall Mount</label>
<label>
<input type="radio" name="installation" value="recessed" />
Recessed</label>
<label>
<input type="radio" name="installation" value="floormount" />
Floor Mount </label>

then catch it like this making sure to clean your data for bad characters


$a = '';
$i = '';

if (isset($_POST['application']) (
$a = mysql_real_escape_string($_POST['application']);
}
if (isset($_POST['installation']) (
$i = mysql_real_escape_string($_POST['installation']);
}

pixeldiver

2:35 am on Jun 28, 2009 (gmt 0)

10+ Year Member



Thanks bkeep,
finally I got this thing working in a test file. I was looking too far to make things working.

There's an other problem I've got: I will need to make some new radio buttons, because I have images instead of radio buttons as an interface and they do not work within the form with <input name="image" type="image"...

I will look around for a solution.

Thank you!