troubleshooting Question

Using Modal's in to Retrieve Data from MySql and Populate Forms

Avatar of Ridgejp
RidgejpFlag for United Kingdom of Great Britain and Northern Ireland asked on
PHPMySQL ServerAJAXjQueryBootstrap
13 Comments1 Solution5084 ViewsLast Modified:
I had this question after viewing Use Select Query to Return Results as a Form.

Hi All,

I had the above question answered earlier today and was hoping to also research a similar solution using modals. I have a select query that's returning a data set using mysql and bootstrap. The code looks like this: -

<table id="table" class="table table-bordered table-striped table-hover">  
				<thead>
					<tr>
						<th class="success text-center">Part_ID</th>
						<th class="success">CAT_ID</th>
						<th class="success text-center">Qty</th>
						<th class="success text-center">Days.42</th>
						<th class="success text-center">Days.14</th>
						<th class="success text-center">+/-</th>
						<th class="success">Supplier</th>
						<th class="success text-center">SFP</th>
						<th class="success text-center">Cost</th>
						<th class="success text-center">Actions</th>        
					</tr>
				</thead>
				<tbody class="searchable">

	<?php

	$query = "select `partID`, `partDescription`, `qtyInStock`, `sfp`, round((sales42D/42),0) as sales42D, round((sales14D/14),0) as sales14D, round((sales14D/14)-(sales42D/42),0) as salesdiff,`supplierCompany`, `itemCost` FROM inventory";

	if (!$result = $mysqli->query($query)) {
		$err
		= "QUERY FAIL: "
		. $query
		. ' ERRNO: '
		. $mysqli->errno
		. ' ERROR: '
		. $mysqli->error
		;
		trigger_error($err, E_USER_ERROR);
		}

	while ($row = $result->fetch_object()) {
		$tr = <<<EOD
				<tr>
					<td class="text-center"> $row->partID </td>
					<td> $row->partDescription </td>  
					<td class="text-center"> $row->qtyInStock </td>
					<td class="text-center"> $row->sales42D </td>
					<td class="text-center"> $row->sales14D </td>
					<td class="text-center"> $row->salesdiff </td>
					<td> $row->supplierCompany </td>
					<td class="text-center"> $row->sfp</td>
					<td class="text-center"> £$row->itemCost </td>
					<td class="text-center"> 
						<div class="dropdown">   
							<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">Options <span class="caret"></span></button>
							<ul class="dropdown-menu" role="menu">
							<li><a href="#">Edit</a></li>
							<li><a href="#">Delete</a></li>
						</div>
					</td>
				</tr> 
EOD;
		echo $tr;}

	?>
			</table>

I wanted to click on the 'Edit' button within the table and it open a form with more detailed information from my inventory table using another select query bound to the row it was linked to. The code provided looked like this (which was great): -

<li><a href="editform.php?partid=$row->partID"">Edit</a></li>

<?php

		$partID = $_REQUEST[ 'partid' ]; //GET THE VALUE FOR postID from URL

		$query = "select `partID`, `partDescription`, `qtyInStock`, `sfp`, round((sales42D/42),0) as sales42D, round((sales14D/14),0) as sales14D, round((sales14D/14)-(sales42D/42),0) as salesdiff,`supplierCompany`, `itemCost` FROM inventory WHERE partID=" . $partID . "";

		if ( !$result = $mysqli->query( $query ) ) {
			$err
				= "QUERY FAIL: "
				. $query
				. ' ERRNO: '
			. $mysqli->errno
				. ' ERROR: '
			. $mysqli->error;
			trigger_error( $err, E_USER_ERROR );
		}

		$row = $result->fetch_object();


		?>


		<form name="editform" action="post">
			<table width="50%" border="0" cellpadding="2" cellspacing="2">
				<tbody>
					<tr>
						<td>partID</td>
						<td><input type="text" name="partID" value="<?php echo $row->partID;  ?>">
						</td>
					</tr>

					<tr>
						<td>partDescription</td>
						<td><input type="text" name="partDescription" value="<?php echo $row->partDescription;  ?>">
						</td>
					</tr>

					<tr>
						<td>qtyInStock</td>
						<td><input type="text" name="qtyInStock" value="<?php echo $row->qtyInStock;  ?>">
						</td>
					</tr>

					<tr>
						<td>sfp</td>
						<td><input type="text" name="sfp" value="<?php echo $row->sfp;  ?>">
						</td>
					</tr>

					<tr>
						<td>sales42D</td>
						<td><input type="text" name="sales42D" value="<?php echo $row->sales42D;  ?>">
						</td>
					</tr>

					<tr>
						<td>supplierCompany</td>
						<td><input type="text" name="supplierCompany" value="<?php echo $row->supplierCompany;  ?>">
						</td>
					</tr>

					<tr>
						<td>itemCost</td>
						<td><input type="text" name="itemCost" value="<?php echo $row->itemCost;  ?>">
						</td>
					</tr>

				</tbody>
			</table>
		</form>

How do I use the same principle to trigger the same information but this time into a modal? I'm conformable with getting the modal to load via the button within the table, but how does the button toggle the data request and how does that look from a php perspective?

J
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros