douyinlai2169 2017-01-05 20:03
浏览 29

执行多个查询然后作为数组输出

This is a search option for a gameID. The SQL is correct as I have tested that in Phpmyadmin. But I'm having trouble displaying the results how I want them to. Currently this code displays the first query exactly how I need them too but every other text box tends to have a '>' in the box instead of the data i need it to display.

I don't think the array code section is correct but I'm having trouble finding a solution as I can't have multiple params in the first array. I've tried for the past few hours to resolve this but with no luck. Is it possible to add many IF statements within the main IF statement to output each IF separately as an array? Any help or suggested reading will be very much appreciated.

if (isset($_POST['submitted'])) {

$category = $_POST ['category'];
$criteria = $_POST ['criteria'];

$query1 = "         
SELECT GameTable.GameID
FROM GameTable
WHERE $category = '$criteria'
";

$query2 = "
SELECT GameTable.GameName 
FROM GameTable 
WHERE $category = '$criteria'
";  

$query3 = "
SELECT Publisher.PubName
FROM Publisher 
JOIN GameTable 
ON Publisher.PubID=GameTable.PubID
WHERE $category = '$criteria'
";  

$query4 = "
SELECT TimePeriod.TimePeriodName
FROM TimePeriod
JOIN GameTable
ON TimePeriod.TimePeriodID=GameTable.TimePeriodID
WHERE $category = '$criteria'
";  

$query5 = "
SELECT Setting.SettingName
FROM Setting
JOIN GameTable
ON Setting.SettingID=GameTable.SettingID
WHERE $category = '$criteria'
";  

$query6 = "
SELECT Mood.MoodName
FROM Mood
JOIN GameTable
ON Mood.MoodID=GameTable.MoodID
WHERE $category = '$criteria'
";  

$query7 = "            
SELECT Weapon.WeaponName
FROM Weapon
JOIN GameWeapon
ON Weapon.WeaponID=GameWeapon.GameWeaponID
JOIN GameTable
ON GameTable.GameWeaponID=GameWeapon.GameWeaponID
WHERE $category = '$criteria'
";  

$query8 = "
SELECT CameraAngle.CameraAngleName
FROM CameraAngle
JOIN GameCameraAngle
ON CameraAngle.CameraAngleID=GameCameraAngle.GameCameraAngleID
JOIN GameTable
ON GameTable.GameCameraAngleID=GameCameraAngle.GameCameraAngleID
WHERE $category = '$criteria'
";  

$query9 = "
SELECT PlayerType.PlayerTypeName
FROM PlayerType
JOIN GamePlayerType
ON PlayerType.PlayerTypeID=GamePlayerType.GamePlayerTypeID
JOIN GameTable
ON GameTable.GamePlayerTypeID=GamePlayerType.GamePlayerTypeID
WHERE $category = '$criteria'
";  

$query10 = "
SELECT GameTable.GameDescription
FROM GameTable
WHERE $category = '$criteria'
";  

//selecting all the data from the game table that makes the search criteria

$result1 = mysqli_query($dbcon, $query1);

$result2 = mysqli_query($dbcon, $query2);

$result3 = mysqli_query($dbcon, $query3);

$result4 = mysqli_query($dbcon, $query4);

$result5 = mysqli_query($dbcon, $query5);

$result6 = mysqli_query($dbcon, $query6);

$result7 = mysqli_query($dbcon, $query7);

$result8 = mysqli_query($dbcon, $query8);

$result9 = mysqli_query($dbcon, $query9);

$result10 = mysqli_query($dbcon, $query10);

if( !$result1->num_rows ) {
if( !$result2->num_rows ) {
if( !$result3->num_rows ) {
if( !$result4->num_rows ) {
if( !$result5->num_rows ) {
if( !$result6->num_rows ) {
if( !$result7->num_rows ) {
if( !$result8->num_rows ) {
if( !$result9->num_rows ) {
if( !$result10->num_rows ) {

  die('No Games found! Please search again');
 //if there are no results to display will inform the user to search a valid data
}
}
}
}
}
}
}
}
}
}


echo "<table class='col-md-12'>"; // displays the searched data as a table


while ($row1 = mysqli_fetch_array($result1)) {

  echo "<form class=col-md-6 action=searchgame.php method=post>";
  echo "<tr> <th> Game ID</th> </tr>";
  echo "<tr>";
  echo "<td>" . "<input class=text-black type=text name=gameid readonly=readonly value=" . $row1['GameID'] . " </td> <br>"; //here i have made the game Id read only so that it is not editable by the administrator

while ($row2 = mysqli_fetch_array($result2)) {
  echo "<tr> <th> Game Name</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=gamename value=" . $row2['GameName'] . " < /td> <br>"; // editable boxes so administator can update


while ($row3 = mysqli_fetch_array($result3)) {
  echo "<tr> <th> Publisher</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=pubid value=" . $row['PubName'] . " < /td><br>";


while ($row4 = mysqli_fetch_array($result4)) {
  echo "<tr> <th> Time Period</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=timeperiodid value=" . $row['TimePeriodName'] . " < /td><br>";


while ($row5 = mysqli_fetch_array($result5)) {
  echo "<tr> <th> Setting ID</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=settingid value=" . $row['SettingName'] . " < /td> <br>"; 


while ($row6 = mysqli_fetch_array($result6)) {
  echo "<tr> <th> Mood</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=moodid value=" . $row['MoodName'] . " < /td><br>";


while ($row7 = mysqli_fetch_array($result7)) {
  echo "<tr> <th> Weapon</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=gameweaponid value=" . $row['WeaponName'] . " < /td><br>";


while ($row8 = mysqli_fetch_array($result8)) {
  echo "<tr> <th> Camera Angle</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=gamecameraangleid value=" . $row['CameraAngleName'] . " < /td><br>";


while ($row9 = mysqli_fetch_array($result9)) {
  echo "<tr> <th> Player Type</th> </tr>";
  echo "<td>" . "<input class=text-black type=text name=gameplayertype value=" . $row['PlayerTypeName'] . " < /td><br>";


while ($row10 = mysqli_fetch_array($result10)) {
  echo "<tr> <th> Game Description</th> </tr>";
  echo "<td>" . "<textarea style=height:200px;width:300px; class=text-black type=text name=gamedescription value=>" . $row['GameDescription'] . "</textarea><br>";
  echo "<td>" . "<input type=hidden name=hidden value=" . $row['GameID'] . " </td>";

  echo "<td>" . "<input class=text-black input-button-rounded type=submit name=update value=Update" . " </td>"; //update button 
  echo "<td>" . "<input class=text-black input-button-rounded type=submit name=delete value=Delete" . " </td>"; //delete button
  echo "</tr>";
  echo"</form>";

}
}
}
}
}
}
}
}
}
}


echo "</table>";


}
  • 写回答

1条回答 默认 最新

  • duanqu9292 2017-01-05 20:22
    关注

    I've solved it, my $row variables in the output didn't match up to the arrays! Such a simple error, but now working!

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计