Jump to content

Can this be shortened?


Kryptix

Recommended Posts

`user1_item1` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item2` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item3` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item4` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item5` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item5` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item7` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item6` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item9` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item10` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item11` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user1_item12` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item1` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item2` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item3` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item4` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item5` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item5` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item7` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item6` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item9` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item10` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item11` LIKE '" . $db->escape($_POST['item_id']) . "' OR `user2_item12` LIKE '" . $db->escape($_POST['item_id']) . "'

 

If there anyway I can do like: `user%_item%`  LIKE '" . $db->escape($_POST['item_id']) . "'?

Link to comment
https://forums.phpfreaks.com/topic/191911-can-this-be-shortened/
Share on other sites

Having 24 columns named like that indicates a bad table design. So the answer is yes you can simplify that, by starting with a good table design.

 

And, no you cannot use wild-cards in column names. You must specify each column name individually.

Well, how would you do it? It's a trade logging system for a RPG. There's 2 players, each with 12 inventory spaces. Every item has to be logged so we can search by item ID. I don't want to have a string in a VARCHAR so I couldn't think of any other way.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.