Jump to content

textarea - database list?


StirCrazy

Recommended Posts

Hi folks,

Firstly can I just say thanks to all the regulars that have helped me recently - thanks guys  :D

I have another question for ya  ;)



I want to set up a post function that on one page has a textarea where I can enter order numbers on each line

EG
[code]<textarea>

23423
23425
36366
23534
64565
34534
24435
25234

</textarea>[/code]


...and then after pressing submit list just those order numbers from database central_orders




How would you do that?

Thanks
S.C>
Link to comment
https://forums.phpfreaks.com/topic/28115-textarea-database-list/
Share on other sites

first, you have to name your textarea so that the variable will be sent, let's go with "orders"

on the submit page
[code]
<?php
        $arr_orders = explode("\n",$_REQUEST['orders']);
        foreach ($arr_orders AS $int_ordernum) {
                // display code for orders here using $int_ordernum to get info
        }

?>[/code]
Many thanks mb81

Still a novice at this ~ so how would I use that in the below code?

[code]<font class="Title"><strong>Preview Orders</strong></font><br>

<form name="email" method="post" action="index.php?page=preview-orders">
<p align="center" class="PlainText" >
<textarea name="orders" rows=17 cols=68>




</textarea>
<center><br><input type="submit" class="mainoption" value="  Send  "></center>
</form>[/code]




[code]$r = my_query("select order,user_id,offer,timedate,browser,trackingid,status from central_orders " . "$where_clause" );


  <table border="1" cellspacing="0" cellpadding="2">
  <tr>
  <th bgcolor="#dddddd">Order Number</th>
  <th bgcolor="#dddddd">User</th> 
  <th bgcolor="#dddddd">Offer</th>
  <th bgcolor="#dddddd">Date / Time</th>
  <th bgcolor="#dddddd">Browser</th> 
  <th bgcolor="#dddddd">SID</th>
  <th bgcolor="#dddddd">Status</th> 
  </tr>
  <?php
    while (list($order,$user_id,$offer,$timedate,$browser,$trackingid,$status) = mysql_fetch_row($r)) {
  ?>
  <tr>
  <td width="75" align="center"><?php echo $order; ?></td>
  <td width="75" align="center"><?php echo $user_id; ?></td>
  <td width="125" align="center"><?php echo $offer; ?></td>
  <td width="110" align="center"><?php echo date("d-m-Y H:i",$timedate); ?></td>
  <td align="center"><?php echo $browser; ?></td> 
  <td width="50" align="center"><?php echo $trackingid; ?></td>
  <td width="50" align="center"><?php echo $status; ?></td>
  </tr>
  <?php
    }
  ?>
 
  </table>[/code]
Based on that code, you can just add these two lines at the top:
[code]
<?php
$arr_orders = explode("\n",$_REQUEST['orders']);
$where_clause = "WHERE order IN ('",implode("','",$arr_orders),"')";
?>
[/code]

I would suggest learning how to use an array from mysql_fetch_array or object from mysql_fetch_object would make more sense, rather than using list();

[quote author=StirCrazy link=topic=115912.msg472156#msg472156 date=1164218490]
getting a parse error, unexpected ','
on this line:-
[code]$where_clause = "WHERE order IN ('",implode("','",$arr_orders),"')"; [/code]

any ideas?


S.C>
[/quote]

Sorry, change the commas to periods (.)
[code]
<?php
$arr_orders = explode("\n",$_REQUEST['orders']);
$where_clause = "WHERE order IN ('".implode("','",$arr_orders)."')";
?>
[/code]
Can anyone work out what is wrong with this code?



This is my my_query function:-
[code]<?php

$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ("Could not connect to database. Try later<BR>");
@mysql_select_db(DB_NAME, $link);

function my_query($sql) {
  global $link;
  $result = @mysql_query($sql, $link);
  if ($result) return $result;
  if (DEBUG_MODE) { error_report(10); };

  return false;
}
  ?>
[/code]




$_REQUEST['credit'] has a list for order numbers from a textarea:-

[code]<?php

$arr_orders = explode("\n",$_REQUEST['credit']);
$where_clause = "WHERE trackingid IN ('".implode("','",$arr_orders)."')";

$r = my_query("select user_id,site,offer,points,timedate,trackingid,status from offer_clicks " . "$where_clause");

  ?>
 
<h1>Preview Accounts</h1><br> 

  <table border="1" cellspacing="0" cellpadding="2">
  <tr>
  <th bgcolor="#dddddd">Site</th> 
  <th bgcolor="#dddddd">User ID</th>
  <th bgcolor="#dddddd">Username</th> 
  <th bgcolor="#dddddd">Offer</th>
  <th bgcolor="#dddddd">Credit</th>
  <th bgcolor="#dddddd">Date / Time</th>
  <th bgcolor="#dddddd">Tracking ID</th> 
  <th bgcolor="#dddddd">Status</th>
  <th bgcolor="#dddddd">Credit</th>
  <th bgcolor="#dddddd">Pending</th>
  <th bgcolor="#dddddd">Reject</th>   
  </tr>
  <?php
    while (list($user_id,$site,$offer,$points,$timedate,$trackingid,$status) = mysql_fetch_array($r)) {
 
$sql = my_query("select username from central_users where id='$user_id'");
list($username) = mysql_fetch_row($sql);
$sql = my_query("select site_name from site_options where site_prefix='$site'");
list($site_name) = mysql_fetch_row($sql); 

  if ('0' == $status) {     
$status = "Clicked"  ;
  }   
  if ('1' == $status) {     
$status = "Credited"  ;
  } 
  if ('2' == $status) {     
$status = "Pending"  ;
  }   
  if ('3' == $status) {     
$status = "Rejected"  ;
  }     
if ($points < 100) {
$points = $points ." Credit";     
}
if ($points > 99) {
$points = "Full Credit";
}

  ?>
  <tr>
  <td width="75" align="center"><?php echo $site_name; ?></td>   
  <td width="75" align="center"><?php echo $user_id; ?></td>
  <td width="125" align="center"><?php echo $username; ?></td>
  <td width="125" align="center"><?php echo $offer; ?></td>
  <td width="100" align="center"><?php echo $points; ?></td> 
  <td width="110" align="center"><?php echo date("d-m-Y H:i",$timedate); ?></td>
  <td width="110" align="center"><?php echo $trackingid; ?></td> 
  <td width="75" align="center"><?php echo $status; ?></td>
  <td width="75" align="center"><INPUT TYPE=RADIO NAME="<?=$trackingid?>" VALUE="<?=$trackingid?>" CHECKED></td>
  <td width="75" align="center"><INPUT TYPE=RADIO NAME="<?=$trackingid?>" VALUE="<?=$trackingid?>"></td>
  <td width="75" align="center"><INPUT TYPE=RADIO NAME="<?=$trackingid?>" VALUE="<?=$trackingid?>"></td> 
  </tr>
  <?php
    }
  ?>
  </table> 
 
  <?php 

  return(0);
}
  ?>[/code]


Problem is it only displays the last order...
any ideas?


S.C>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.