Need Help - Javascript passing value

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Post 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???
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
Post Reply