Jump to content

[SOLVED] using substr() on dropdown select list


richrock

Recommended Posts

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

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



	}

?>

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.