1

hye all , i have problem with echo inside echo . the original code is like this:

<input type="button" value="Update" onClick="window.location.href='edit_walkinnew.php?action=update&No=<?php echo $row['No'];?>'">

i want to echo this "Update button" into my search result , i writing like this :

echo '<td><input type="button" value="Update" onclick="window.location.href=\'edit_walkinnew.php?action=update&No=<?php echo $No; ?>\'"></td>';

the problem is when i click on that update button , the adress will be like this(the no is not called):

edit_walkinnew.php?action=update&No=

instead of

edit_walkinnew.php?action=update&No=847

(this is the code suppose to be) , i believe the problem is happen because of this line

php echo $No;

updated : When i clicked on Update the $No is still not appear

     $sql="SELECT * FROM walkin2bck WHERE Date LIKE '%$search%' OR Name LIKE '%$search%' OR NRIC_No LIKE '%$search%' OR ContactNo LIKE '%$search%' OR Financial_Institution LIKE '%$search%' OR TypeofComplaint LIKE '%$search%' OR Typeofcase LIKE '%$search%' OR RefNo LIKE '%$search%' OR AttendBy LIKE '%$search%'";
    $result = mysqli_query($con,$sql);
    $No = $row['No'];
    $total = 0;
    $total = mysqli_num_rows($result);
     echo "Searching  for : ".$search."<br/>";
     echo "Total Result : ".$total."<br/>";

     if (mysqli_num_rows($result) > 0) {
        echo "<table border='1' cellpadding='11'>
                <tr>
                <th>No</th>
                <th>Date</th>
                <th>Name</th>
                <th>NRIC No</th>
                <th>Contact No</th>
                <th>Financial Institution</th>
                <th>Type of Complaint</th>
                <th>Type of case</th>
                <th>Ref No</th>
                <th>Attend By</th>
                <th>Action</th>";

         while($row = mysqli_fetch_assoc($result)) {
            //echo "RG: " . $row["Registered_Date"]. " - T: " . $row["Type"]. " R" . $row["Ref_No"]. "<br>";
            echo "<tr>
            <td>".$row["No"]."</td>
            <td>".$row["Name"]."</td>
            <td>".$row["Name"]."</td>
            <td>".$row["NRIC_No"]."</td>
            <td>".$row["ContactNo"]."</td>
            <td>".$row["Financial_Institution"]."</td>
            <td>".$row["TypeofComplaint"]."</td>
            <td>".$row["Typeofcase"]."</td>
            <td>".$row["RefNo"]."</td>
            <td>".$row["AttendBy"]."</td>";
            echo '<td><input type="button" value="Update" onClick="window.location.href=\'edit_walkinnew.php?action=update&No=' . $No. '\'"></td>';
        }
        echo "</table><br/>";
        echo "<a href='walkindetailnew.php'>Back to main</a>";
     }else {
        echo "0 results";
    }




mysqli_close($con);

} 

}

aNNAComey
  • 11
  • 2

1 Answers1

3

You don't need <?php echo ?> inside the echo, it will just be treated as a string. Since you are already echoing the line what you need to break out of the echo with single quotes so that PHP can insert your variable like so:

echo '<td><input type="button" value="Update" onclick="window.location.href=\'edit_walkinnew.php?action=update&No=' . $No. '\'"></td>';

Updated answer to updated question:

You are setting $No = $row['No'] outside of the while loop. You have to set it inside the while loop or change your echo statement to include $row:

echo '<td><input type="button" value="Update" onclick="window.location.href=\'edit_walkinnew.php?action=update&No=' . $row['No']. '\'"></td>';

keeg
  • 3,990
  • 8
  • 49
  • 97
  • @Nick post is as an answer and I'll be happy to delete – keeg Aug 29 '18 at 01:57
  • Then you probably should have answered it instead of commenting. :) Besides, your comment is incorrect, and user37's comment is not as clear and explanatory as keeg's. – FoulFoot Aug 29 '18 at 01:58
  • 1
    thank you so much for all that contribute in answering the questions! – aNNAComey Aug 29 '18 at 02:02
  • probably worth noting that you don't need to concatenate, there are teeny tiny speed improvements with a comma. For readability this works too echo ""; – Sarah K Aug 29 '18 at 02:19
  • update , i've put my code , the $No still not appear – aNNAComey Aug 29 '18 at 02:47
  • you are setting `$No` out side of the loop you need to set `$No = $row['No']` inside your while loop: `while($row = mysqli_fetch_assoc($result)) {` – keeg Aug 29 '18 at 03:01
  • 1
    @keeg thank you so much sir ,and its working now , appreciate your help , thanks again – aNNAComey Aug 29 '18 at 03:04
  • hye , can someone answer with other posted question , tq so much – aNNAComey Sep 25 '18 at 02:54