Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
The $file-name should be for example: a.pdf,b.pdf,c.pdf,d.pdf respectively.
But why I cannot assign the value into the checkbox?
please help/__\
while($row = Mysqli_fetch_array($result))
{
$file-name = $row['Name'] . ".pdf";
echo "<tr>";
echo "<td><input type='checkbox' name='q1[]'value=<?php echo $filename ?>' > </td>";
}
Per the comments above, try the following:
while($row = Mysqli_fetch_assoc($result))
{
$filename = $row['Name'] . ".pdf";
echo "<tr>";
echo "<td><input type='checkbox' name='q1[]' value='".$filename."' /> </td>";
}
As the comments to your question mentioned you were assigning $file-name (an invalid variable name in PHP) and trying to use a (presumably) unassigned variable: $filename you also were missing an opening single-quote for the value attribute which could prevent it from properly rendering, and you can use string concatenation instead of trying to echo-inside-an-echo.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Currently my code consists of
$sql = "SHOW columns FROM tblexercise";
$result = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
foreach ($row as $field => $value) {
echo "<td>" . $value . "</td>";
}
echo "</tr>";
}
This allows me to show the column names but it also includes all the attributes and types etc.
is there any way to show just the column name?
You don't need a loop inside a loop. You only need one foreach loop and then you can access the key Field which holds the name of the column. The query SHOW COLUMNS is explained in the MySQL doc. You can check in that link what are the results of this query and their sample values. Then you can decide which values you want to access.
$result = $conn->query("SHOW columns FROM tblexercise");
foreach ($result as $row) {
echo "<tr>";
echo "<td>" . $row['Field'] . "</td>";
echo "</tr>";
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm using a html table where each row and column has his own ID (e.g. name="23_3").
But this ID is made of 2 variables $calUser= $x['idTask'] . "-" . $y['idTime'];
This is how I explode() it:
list($uTask,$uTime) = explode("-", $_POST['$calUser'], 2);
But it's not working any ideas?
EDIT
Sorry forgot the input
<input type='text' name='" . $calUser . "' value='$calUser'>
Input in your case should be:
<input type='text' name='calUser' value='". $calUser . "'>
Validate this by taking a look at the produced page's soure code.
After that you can get the content by calling:
list($uTask,$uTime) = explode("-", $_POST['calUser'], 2);
But as with all user provided content ($_POST), check if the content really is within the range of expected values to prevent XSS and injection attacks on your page.
Fist of all, you are trying to explode $calUser, or the value corresponding to the $calUser key?.
I think you should do:
list($uTask,$uTime) = explode("-", $_POST[$calUser], 2);
Remove the quotes on the $_POST key, or you will be asking for the literal '$calUser'
EDIT
Also, your input tag must be:
<input type='text' name='" . $calUser . "' value='" . $calUser ."'>
Altough i dont know if rou are using a string for the tag, or directly echoing to ouput, so some like:
<?php
echo "<input type='text' name='" . $calUser . "' value='" . $calUser ."'>";
Would be advised, and my favorite syntax:
<?php
echo "<input type='text' name='{$calUser}' value='{$calUser}'>";
I like the brackets, as are more friendly even with SQL...
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
i've got the following code
$data = mysql_query(
"SELECT md.*, qr.*
FROM moduleDetails md
LEFT JOIN qResponses qr
ON qr.userno = md.userno");
print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
print "<tr>";
print "<th>Faculty</th> <td>".$info['faculty'] . "</td>";
print "<th>Module Code</th> <td>".$info['moduleCode'] . "</td>";
print "<th>Date Started</th> <td>".$info['dateStarted'] . "</td>";
print "<th>Module Title</th> <td>".$info['moduleTitle'] . "</td>";
print "<th>School</th> <td>".$info['school'] . "</td></tr>";
}
print "</table>";
it's giving me a error on line 31, which is the $info = mysql_fetch.... etc
What have i done wrong?.. i can't see a fix for this, it wasnt working fine before before i involved two tables.. any help would be great - cant see whats wrong - new to joining tables.
Probably you get no results from the query. Execute the query to verify it gives result and check you have results before trying to fetch them
if (mysql_num_rows($data) == 0)
die("No Records");
elseif (mysql_num_rows($data) > 0)
{
while($info = mysql_fetch_array( $data ))
{
...............
}
}
else { die("Something else went wrong"); }
Or even better wrap it in a try/catch
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
This is driving me crazy. The table renders correctly in that the column headers are all correct and the first column is correct but then the second column is skipped and the data that should be there is in the 3rd column and the 3rd in the 4th column etc. When I look at the page source everything looks correct. But when I look at "elements" in Chrome's developers tools there is the extra . Here is the code:
echo '<table id="bordered">';
echo '<thead>';
echo '<tr>';
echo '<th></th>';
foreach($products as $product){
/*#var $product Products */
echo '<th>',$product->getProductName(),'</th>';
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach($customers as $cust){
echo '<tr>';
echo '<td>',$cust->getCustomerName(),'<td>';
$prod = ForecastDisplay_db::getProductsQuantityForCustomer($cust, $products);
$i=0;
foreach($prod as $quantity){
$i++;
if($i == 1){
echo '<td>First Run</td>';
}else{
echo '<td>', $quantity['id'],' ',$quantity['quantity'],'</td>';
}
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
I added that 'First Run' to make sure there wasn't a null in the first positions of the array's but there isn't. Anyone have an idea why that column is being skipped?
You did not closed the td tag correctly.
echo '<td>',$cust->getCustomerName(),'<td>';
should be
echo '<td>',$cust->getCustomerName(),'</td>';
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am querying my database and dumping the data into an HTML table. One of my database keys is called "time_expire", with a value of -1 meaning never. Therefore, to show something to the effect of "never" in the HTML table instead of the raw data I am attempting to change the variable before it is echo'd.
This is my code
<?php
$sql = "SELECT * FROM penalties ORDER BY id DESC";
$result = mysql_query($sql);
while ($rows = mysql_fetch_array($result)) {
if ($rows['time_expire'] = '-1') {
$rows['time_expire'] = '<span class="label label-important">Permanent</span>';
}
echo "<tr>";
echo '<td>' . $rows['id'] . '</td>';
echo "<td>" . $rows['client_id'] . "</td>";
echo "<td>" . $rows['type'] . "</td>";
echo "<td>" . date('m/d/Y', $rows['time_add']) . "</td>";
echo "<td>" . $rows['duration'] . "</td>";
echo "<td>" . $rows['time_expire'] . "</td>";
echo "<td>" . $rows['reason'] . "</td>";
echo "</tr>";
}
?>
This code does not error, however every row in my HTML table has an expiration value of "never", even if the the raw data is different.
This seems to be a common typo in the if statemenet
if ($rows['time_expire'] = '-1') [
^
|
If you want to the interpreter spot these for you, try using yoda conditions like this:
if ('-1' = $rows['time_expire'])
This form will create error however the correct forms both work ok:
'-1' == $rows['time_expire']
or
$rows['time_expire'] == '-1'
I think it is supposed to be:
if ($rows['time_expire'] == '-1')
not
if ($rows['time_expire'] = '-1')
First what type is time_expire?
If time_expire is numeric then you should change the condition to:
if ($rows['time_expire'] == -1) which will evaluate properly.
Secondly your condition checking is actually assigning the value to $rows['time_expire'] with single =, it should be double = like ==.
Try changing If condition to if ($rows['time_expire'] == '-1'). Right now what your condition says that variable $rows['time_expire'] is equal to '-1' which is always returning true.It might get you in the unlimited looping.