richrock Posted October 2, 2008 Share Posted October 2, 2008 Hi, Well, my project's getting there... Thankfully! Just a little stuck on the use of substr() - I've been using php.net, but my usage isn't really covered there. I've got a drop-down select list, and here's the code for that : <?php if ($_POST['name']) { $uid = $_POST['name']; //now select the lot to edit. $getLot = "SELECT * FROM jos_bid_auctions WHERE userid = ".$uid.""; $resLot = mysql_query($getLot) or die(mysql_error()); $querysalenum = "SELECT * FROM jos_bid_categories ORDER BY id"; $resultsalenum = mysql_query($querysalenum) or die(mysql_error()); // generate the rows $row_selectLot = mysql_fetch_assoc($resLot); $totalRows_selectLot = mysql_num_rows($resLot); $title = $row_selectLot['title']; ?> <tr> <td><?php echo LOT_salenum; ?> </td> <td><form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" name="addlot" enctype="multipart/form-data"> <select name="salenum"> <option value='none'>-- Select An Instrument To Edit --</option> <?php do { if ($salenum==$row_selectLot['id']) { echo "<option value ='".$row_selectLot['id']."' selected>".$row_selectLot['id'].", ".substr('$row_selectLot["title"]',0,10)."</option>"; } else { echo "<option value ='".$row_selectLot['id']."'>".$row_selectLot['id'].", ".substr('$row_selectLot["title"]',0,10)."</option>"; } } while ($row_selectLot = mysql_fetch_assoc($resLot)); $rows = mysql_num_rows($resLot); if($rows > 0) { mysql_data_seek($resultname, 0); $row_selectLot = mysql_fetch_assoc($resLot); } ?> </select> </td> </tr> <?php } ?> As you can see, I've tried using substr to limit the length of text returned from the 'title', as this makes for quite a large dropdown!! It's not working though. I also tried to define the 'title' as $title outside of the dropdown, and again no dice. Any pointers would be well appreciated on this. Rich Link to comment https://forums.phpfreaks.com/topic/126730-solved-using-substr-on-dropdown-select-list/ Share on other sites More sharing options...
waynew Posted October 2, 2008 Share Posted October 2, 2008 Try <?php if ($_POST['name']) { $uid = $_POST['name']; //now select the lot to edit. $getLot = "SELECT * FROM jos_bid_auctions WHERE userid = ".$uid.""; $resLot = mysql_query($getLot) or die(mysql_error()); $querysalenum = "SELECT * FROM jos_bid_categories ORDER BY id"; $resultsalenum = mysql_query($querysalenum) or die(mysql_error()); // generate the rows $row_selectLot = mysql_fetch_assoc($resLot); $totalRows_selectLot = mysql_num_rows($resLot); $title = $row_selectLot['title']; ?> <tr> <td><?php echo LOT_salenum; ?> </td> <td><form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" name="addlot" enctype="multipart/form-data"> <select name="salenum"> <option value='none'>-- Select An Instrument To Edit --</option> <?php do { if ($salenum==$row_selectLot['id']) { echo "<option value ='".$row_selectLot['id']."' selected>".$row_selectLot['id'].", ".substr($row_selectLot["title"],0,10)."</option>"; } else { echo "<option value ='".$row_selectLot['id']."'>".$row_selectLot['id'].", ".substr($row_selectLot["title"],0,10)."</option>"; } } while ($row_selectLot = mysql_fetch_assoc($resLot)); $rows = mysql_num_rows($resLot); if($rows > 0) { mysql_data_seek($resultname, 0); $row_selectLot = mysql_fetch_assoc($resLot); } ?> </select> </td> </tr> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/126730-solved-using-substr-on-dropdown-select-list/#findComment-655470 Share on other sites More sharing options...
richrock Posted October 2, 2008 Author Share Posted October 2, 2008 Sweet! So it was just a " & ' formatting typo. I'll remember that in the future! Thanks a lot. Rich Link to comment https://forums.phpfreaks.com/topic/126730-solved-using-substr-on-dropdown-select-list/#findComment-655475 Share on other sites More sharing options...
waynew Posted October 2, 2008 Share Posted October 2, 2008 You had encased: substr('$row_selectLot["title"]',0,10) your array inside single quotes! Simple mistake. Not the end of your career. Link to comment https://forums.phpfreaks.com/topic/126730-solved-using-substr-on-dropdown-select-list/#findComment-655477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.