mySQL Multiple Queries Solution

cronaldo4ever

New Member
I'm trying to build a CMS for a website that I'm building and I need to be able to edit the article's that were saved to the database. The problem I'm facing is I have a lot of \[code\]query\[/code\] statements 1 that's selecting all the articles fields values for my inputs and then another one that's selecting everything from my categories table (For a Select Drop Down with all the categories I have for options), what would be the best way to get all the records from categories and only the record that has the art_id that's = to the one I'm passing through URL.TABLE CATEGORIES\[code\]cat_id cat_name1 soccer2 baseball3 basketball\[/code\]TABLE ARTICLES\[code\]art_id art_cat_id art_title1 1 lorem\[/code\]HTML / PHP\[code\]<?php $sql_articles = "SELECT art_id, art_cat_id, art_title, cat_id, cat_name FROM app_articles LEFT JOIN app_categories ON app_articles.art_cat_id = app_categories.cat_id WHERE art_id =".$_GET['art_id']; $result = query($sql_articles);if($result===false) { echo("query failed");}else { $row = mysqli_fetch_array($result) ?><form id="articles" action="" method="post"><input type="text" name="title" value="http://stackoverflow.com/questions/15737252/<?php echo $row['art_title']; ?>"><select name="category"> <option value="http://stackoverflow.com/questions/15737252/<?php echo $row['art_cat_id'] ?>" selected="selected"> <?php echo $row['cat_name'] ?> </option> <?php $sql_categories = "SELECT cat_id, cat_name FROM app_categories"; $result = query($sql_categories); if($result===false) { echo("Query Fail"); } else { while( $data = http://stackoverflow.com/questions/15737252/mysqli_fetch_array($result)) { if ($row['art_cat_id'] == $data['cat_id']) continue; ?> <option value="http://stackoverflow.com/questions/15737252/<?php echo $data['cat_id'] ?>"> <?php echo $data['cat_name'] ?> </option> <?php } }?></select><input type="submit" value="http://stackoverflow.com/questions/15737252/Save"></form><?php }?>\[/code\]I Guess what I'm asking is that is it possible to do a sql statment that will return something like \[code\]art_id art_cat_id art_title art_slug art_company cat_id cat_name1 1 lorem lorem lorem 1 soccer 2 baseball 3 basketball\[/code\]So I can do this is 1 statement, thanks in advance for anyhelp!
 
Back
Top