Page 2 of 2

Posted: Sun Oct 16, 2005 7:34 am
by pido
foobar wrote:Edit: I looked through your code and I don't have a clue what the hell you're trying to do. Your code prints out an item's info based on its ID. What else do you want it to do?
Hmm.. first Im' sorry about my crappy language :P what I'm trying to do is just to put the item's info in each column after the user typed a Part Number in text field, that's it!!
I tried to made the Part Number permanent after the page refreshing last night, it's worked. And I don't know for the others Part Number I think it will refresh all the PN in field =S will try later.... Or do you have any solution about what im trying to do foobar???

Posted: Sun Oct 16, 2005 9:51 am
by foobar
pido wrote:
foobar wrote:Edit: I looked through your code and I don't have a clue what the hell you're trying to do. Your code prints out an item's info based on its ID. What else do you want it to do?
Hmm.. first Im' sorry about my crappy language :P what I'm trying to do is just to put the item's info in each column after the user typed a Part Number in text field, that's it!!
I tried to made the Part Number permanent after the page refreshing last night, it's worked. And I don't know for the others Part Number I think it will refresh all the PN in field =S will try later.... Or do you have any solution about what im trying to do foobar???
OK. So you want to do as follows:

1. Type PartNumber into text field.
2. Get data for that PartNumber from DB.
3. Display data pertaining to that PartNumber.

Here's a barebone solution:

Code: Select all

<?php

$printform = true;

if (is_numeric($_GET['partnum'])) {
  $sql = sprintf('SELECT * FROM thetable WHERE thepartnum = %d', $_GET['partnum']);
  $rs = mysql_query($sql);
  if ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
    $item = $row;
    $printform = false;
?>
<table>
<tr>
<td>SomeField</td><td><?= $item['somefield'] ?></td>
</tr>
</table>
<?php
  }
  else {
    $printform = true;
  }
}

if ($printform) {
?>
<form method="get">
  Partnum:<input type="text" name="partnum" />
  <br  /><input type="submit" />
</form>
<?php
}
?>
Bear in mind that this isn't very elegant, but it should get the job done.