Jump to content

Need Help in Matching the Two Data from the Codes against Data from Database


php_padawan

Recommended Posts

Can you please help and advice me the best way to approach this requirement?

 

As you can see, I have three columns.  The First Row, Second Row and Third Row.  I already managed to accomplish the First and Third Row, but this time, it is a bit challenging.  I need to match the data found in First and Second Row to come up with the Third Row.  I attached a copy of my table for your reference (testdb.txt).

 

For example:

 

If the value of the First Row is 's_Step1' and the Second Row is '1' the value of the Third Row should be 'Women'.

 

If the value of the First Row is 's_Step2' and the Second Row is '3' the value of the Third Row should be 'Straight Women' and so on and so forth.

 

Please guide me the best way to approach this.  Thanks :)

 

Here is what I have accomplished so far:

 



<html>
<head>
<title>JMData Decode</title>
</head>
<body>

<?php
$JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}";

$dec = (json_decode($JMData));

echo "<table border = 1>";
echo "<tr><td>First Row</td><td>Second Row</td><td>Third Row</td></tr>";
foreach ($dec as $key => $value)
{
echo "<tr><td>". $key."</td><td>". $value ."</td><td>$nbsp</td></tr>";
};
echo "<table/>";

?>

</body>
</html>

testdb.txt

Edited by php_padawan
Link to comment
Share on other sites

That table is a mess.  It also doesn't hold a record that matches the sample request that you provided.  You really should fix your tables before doing anything else.

 

Hi Sir,

 

Please refer to the new table arrangement that I created.  This time, I made different tables for different steps.

Link to comment
Share on other sites

here is my most updated code, I have managed to connect to database and also return the data on the HTML page.  Still, my problem is how to compare two data to return the equivalent data on the third row but I am working on it.  I am still researching what is the best approach for this.

<html>
<head>
	<title>JMData Decode</title>
</head>
<body>
<?php
$JMData = "{\"a_stepActual\":\"99\",\"a_StepReached\":\"99\",\"a_ShowBack\":\"1\",\"a_Similar\":\"\",\"a_JMStarted\":\"1\",\"a_GarmentStatus\":\"2\",\"s_Step1\":\"1\",\"s_Step2\":\"3\",\"s_Step3\":\"7\",\"s_Step4\":\"19\",\"s_Step4_s\":\"2\",\"s_Step5\":\"22\",\"s_Step5_s\":\"2\",\"s_Step6\":\"2816\",\"s_Step7\":\"2819\",\"s_Step8\":\"2821\",\"s_Step8_s\":\"2\",\"s_Step8_r\":\"3\",\"s_Step9\":\"36\",\"s_Step9_s\":\"0\",\"s_Step9_r\":\"0\",\"s_Step10\":\"2826\",\"s_Step10_s\":\"2\",\"s_Step10_r\":\"0\",\"s_Step11\":\"2830\",\"s_Step11_s\":\"2\",\"s_Step11_z\":\"0\",\"s_Step11_r\":\"3\",\"s_Step12\":\"2836\",\"s_Step12_s\":\"0\",\"s_Step12_z\":\"0\",\"s_Step12_r\":\"0\",\"s_Step13\":\"44\",\"s_Step13_s\":\"2\",\"s_Step13_z\":\"1\",\"s_Step13_b\":\"20\",\"s_Step14\":\"47\",\"s_Step14_s\":\"2\"}";

$dec = (json_decode($JMData));

echo "<table border = 1>";
            echo "<tr><td>First Row</td><td>Second Row</td><td>Third Row</td></tr>";
    foreach ($dec as $key => $value)
        {
            echo "<tr><td>". $key."</td><td>". $value ."</td><td>$nbsp</td></tr>";
        };
echo "<table/>";
?>

<?php
$con=mysqli_connect("localhost","test","test","db_test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM Step1Table");
echo "</br></br>";
echo "<table border = 1>";
while($row = mysqli_fetch_array($result))
  {
  echo "<tr>
           <td>".$row['id']."</td>
           <td>".$row['StepWithoutQuotations']."</td>
           <td>".$row['StepValue']."</td>
           <td>".$row['StepWithQuotations']."</td>
           <td>".$row['InternalReference ']."</td>
       </tr>";    
  }
echo "<table/>";
mysqli_close($con);
?>


</body>
</html>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.