PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
// get the id from the URL request
$feature_section = $_REQUEST['feature_section_name'];
// retrieve the row from the database
$query = "SELECT feature_id, feature_title, feature_date, feature_section FROM featurearticles WHERE feature_section='$feature_section' ORDER by feature_id DESC ";
The issue is that this query seems to only return one item with the correct feature section name when I want it to return all the items with the same feature section name.
I have few things to tell you which are much more important...
1. Use $_GET instead of $_REQUEST. It is a better approach if you care about security.
2. mysql_real_escape_string()
3. Google for "sql injection".
4. In your query, why do you select "feature_section" if you know that all the results will have the same feature_section anyway?
// get the id from the URL request
$feature_section = $_GET['feature_section_name'];
// retrieve the row from the database
$result=mysql_query('SELECT feature_id, feature_date, feature_section, feature_title FROM featurearticles WHERE feature_section="'.mysql_real_escape_string($_GET['feature_section_name']).'" ORDER by feature_id DESC');
But I still get the same result - one item listed rather than several
I'm not sure I understand your question about why I select by feature_section. I thought that I had to include all the table items that I wanted to use at any stage of the query in that initial query (like the id, date, title, section etc). As my name would suggest - I'm fairly new at this.
Any tips about how to get it to list all the items with that particular feature_section_name?
Thank you for your patience with me. I checked and there's definitely more than one item with the same feature_section in the table.
I'll try to explain what I was attempting to do - just don't laugh ok?
So the URL has a feature section name appended to it which comes from another separate table (the item name is feature_section_name).
So in my probably muddled thinking I was trying to associate this item (feature_section_name) from the URL to something on the current page so that I could then compare it to an item (feature_name) in the other table within the query. Sort of like this in plain speech:
thing1 = thingappendedtourl
select * from table where thethingIwanttolist = thing1
Show all of your code. I suspect that the query is returning the data properly but the code is not accessing it correctly. Also, run that exact same query in your DB admin tool (phpMyAdmin, MySQL Administrator, SQLYog, etc) to make sure that the result you would get under the correct code conditions is what you are getting here.