Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Basic SQL Help

Featured Replies

Hi All,

 

Wondering if you can quickly help me with the following issue.

 

I'm trying to get the following to work with no avail :(

 

"SELECT * FROM mg_gallery_tbl WHERE category='$cat_name' AND second ='$cat_name' ORDER BY 'photographer';"

Thanks in advance

Hi All,

 

Wondering if you can quickly help me with the following issue.

 

I'm trying to get the following to work with no avail :(

 

"SELECT * FROM mg_gallery_tbl WHERE category='$cat_name' AND second ='$cat_name' ORDER BY 'photographer';"

Thanks in advance

Try this

 

"SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' AND second ='".$cat_name."' ORDER BY photographer ASC";

 

And also the ; was in the wrong place on your code it should of been after the "

Some extra information would help

What's happening/not happening that shouldn't/should at the moment

If you get mysql errors have you echo'd out the query and the mysql_error() to see what problems it shows?

  • Author

Hi,

 

When a user uploads a photo, they can assign it to more then one category from choices in two drop down boxes.

 

At the moment, the following code works fine in displaying the pictures in one category:

 

("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' ORDER BY photographer ASC");

 

But when i try the following code to display pictures which are in more then one category:

 

("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' AND second ='".$cat_name."' ORDER BY photographer ASC");

 

No pictures at all display?

Hi,

 

When a user uploads a photo, they can assign it to more then one category from choices in two drop down boxes.

 

At the moment, the following code works fine in displaying the pictures in one category:

 

("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' ORDER BY photographer ASC");

 

But when i try the following code to display pictures which are in more then one category:

 

("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' AND second ='".$cat_name."' ORDER BY photographer ASC");

 

No pictures at all display?

 

 

People on this forum prob need more info to find out the problem.

People on this forum prob need more info to find out the problem.

 

I second that :good:

 

At a guess (and several assumptions), try this:

 

("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' OR second ='".$cat_name."' ORDER BY photographer ASC")

I second that :good:

 

At a guess (and several assumptions), try this:

 

("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' OR second ='".$cat_name."' ORDER BY photographer ASC")

 

Well actually that would pull ether from the fields category or second and im guessing he wants both to be pulled at the same time from what hes mentioned so far :)

  • Author

Well actually that would pull ether from the fields category or second and im guessing he wants both to be pulled at the same time from what hes mentioned so far :)

 

Thats correct webdesigner93 i want both to be pulled at the same time.

 

category='".$cat_name." (Pictures 1st category is stored)

second='".$cat_name." (Pictures 2nd category is stored)

 

Just not sure how to get both at the same time?

Well actually that would pull ether from the fields category or second and im guessing he wants both to be pulled at the same time from what hes mentioned so far :)

 

No it wouldn't

 

product    | category | second
------------------------------
bone       | dog      | NULL
collar     | dog      | cat

 

 

 

$cat_name = 'dogs';

$cat_name2 = 'cats';

 

"SELECT * FROM `mg_gallery_tbl` WHERE `category`='$cat_name' OR `second` ='$cat_name2' ORDER BY `photographer` ASC"

You'd then need to loop through each result.

No it wouldn't

 

product    | category | second
------------------------------
bone       | dog      | NULL
collar     | dog      | cat

 

 

 

$cat_name = 'dogs';

$cat_name2 = 'cats';

 

"SELECT * FROM `mg_gallery_tbl` WHERE `category`='$cat_name' OR `second` ='$cat_name2' ORDER BY `photographer` ASC"

You'd then need to loop through each result.

 

I thought OR was used to choose from one or the other not both

I thought OR was used to choose from one or the other not both

The OR will return the table row if either category or second = $cat_name.

 

If you use AND then both category and second must = $cat_name to return the row.

 

I'm unclear exactly what you want to achieve.

SELECT * FROM `mg_gallery_tbl` WHERE '$category' IN(`category`, `second`) ORDER BY `photographer` ASC

Like that? If either the category column or second column contain the $category that row will match

 

  • 2 months later...
  • Author

Hi All,

 

Sorry it's took me so long to reply, but i have not been doing much website design recently due to a new job.

 

I just wanted to thank everyone for their input and mention that the following code solved my issue :)

 

("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' OR second ='".$cat_name."' ORDER BY photographer ASC")

 

Thanks once again :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.