php_padawan Posted May 23, 2013 Share Posted May 23, 2013 (edited) 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 May 23, 2013 by php_padawan Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 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. Quote Link to comment Share on other sites More sharing options...
php_padawan Posted May 23, 2013 Author Share Posted May 23, 2013 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. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 where is the new table arrangement? Quote Link to comment Share on other sites More sharing options...
php_padawan Posted May 24, 2013 Author Share Posted May 24, 2013 where is the new table arrangement? Sorry, sir. I think it did not attach last night. here is the attachment that I was referring to: newtable.txt Quote Link to comment Share on other sites More sharing options...
php_padawan Posted May 24, 2013 Author Share Posted May 24, 2013 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> Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted May 24, 2013 Share Posted May 24, 2013 That's still not right, let's work this through together. What does s_Step define? what is the difference between s_Step1 and s_Step2? Why store the same info in different formats? what is the significance of the StepValue? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.