I found a JSON dump of items for a game I play
http://mooshe.pw/files/items_rs3.json
I want to be able to search/find the item's id by searching/inputting the name.
ex: Search 'dwarf remains' and get the number 0 returned (does the name need to be case sensitive and if so can I make it so it isn't?)
So far all I have is this
$itemName = $_GET['name'];
But once I have the name, I don't know how to convert it to the id number prefixing the object which I need
Edit: Sorry for not being so clear - my end goal is to be able to input a 'name' of an item, and I then need to convert the name to the ID (?) that prefixes the relevant object so I can then pass it on to an API and gather stats etc.
How would I convert the name to the ID e.g. Dwarf remains to 0?
Related
I am new in laravel and i am developing an application that I need to display the persons first and last name upon registering on my system. But I am finding it it hard to achieve this instead my code retrieves all the first and last names from my table if i use the instance $contact =contacts::all();
My table named contact has fields like fname, lname,email,phone, body, updated_at,...
I have tried using the ...all()->pluck() to select only the first name and last name but my views displays everything first and last name from the table. I can do it in my views but i need your help in my controller.
Here is my controller
$contact =contacts::all()->pluck('lname','fname').
Anyone with an idea please
-> contacts::all() --- This will result all the data in contacts model
-> contacts::first() --- This will result only single row. please add a where condition with this for required result.
e.g contacts::where('name','=','abc')->first();
contacts::all() will retrieve every single row. If you want to limit the selection to contacts that only have a certain first/last name, then you'll want to use where and get(), which will only get those particular rows:
$fname = 'John';
$lname = 'Doe';
contacts::where('fname', $fname)->where('lname', $lname)->get();
The two variables, of course, would be populated with whatever you're looking for. You can also pass in a comparison as the second parameter, in case you want to check for not equals, LIKE (good for case insensitive searches or wildcard searches), or greater than/less than for numbers and dates.
contacts::where('fname', '=', $fname)->where('lname','=', $lname)->get();
Note that this will bring up everyone with the name John | Doe. It may not be the person who just registered. For that, you'll want to save the user ID somewhere such as in the session after they register, and instead look for that id, which will bring up only 1 record instead of a collection of records that get() would provide.
contacts::find($id);
I do not where to start bu I will be as precise as I can be. There are over 200 customer in the database. I use php.
I made 2 calculations and assigned new values into an array but the results of these calculations will be used in another calculation. When I click on the calculate button it should first take the data from the arrays ($snduz=array_values($array5)[0]; and $test=array_values($array4)[0]; and $snduz=array_values($array5)[1]; and $test=array_values($array4)[1]; so on) that belong to related id put that value into the formula and calculate.
When I put the arrays 1 by 1 it works e.g.
$array5[] = ($sab1*(($test-$ort)/$sdsp)+$sab2);
$snduz=array_values($array5)[0];
$snduz1=array_values($array5)[1];
$snduz2=array_values($array5)[2];
.....
$array4[] = ($tams*$enku)/$row4['sn'];
$test=array_values($array4)[0];
$test1=array_values($array4)[1];
$test2=array_values($array4)[2];
...
but I want to get them calculated automatically
i have an array (Car, SUV, Truck, Bike) that's used in a form. when the option is selected the value is saved to the customers account in database. Value is the array position (eg: 0, 1, 2, 3).
I want this info to be displayed on another page in a table using php as i'm using magento. Currently it only displays the database saved value (0,1,2,3), but i want it to show as ((Car, SUV, Truck, Bike). How do i do this?
i need a way to make it know that 0=Car, 1=SUV, 2=Truck, 3=Bike)
heres what the table looks like now:
The make column represents the vehicle manufacturer (toyota, honda, etc)and type represents (car, bike, suv)
Please help!
Make the table field type an enum that matches the array you specified.
More Details
An ENUM data type is an array that maps a key to a value. If you change the column type to an enumeration, then your Database will display an human readable value instead of a number (e.g., Car, SUV, Truck, Bike).
Also, you can interact with the enum using the Key or the Value so you shouldn't have to change your current implementation.
I'm working on creating an import script to migrate data from an Excel spreadsheet that a client is providing, and converting each row into a WordPress post. So far, I've got the posts being created and all custom fields being filled in properly...except for one.
One of the fields is Associated Parts. I'd like to use the Post Object for this field, but I can't seem to find any documentation on the formatting to use in order to assign a post object (or preferably multiple objects) to this field's value via my PHP script.
The following is an example of some code that I'm using to populate the "specifications" repeater field that has two sub fields, label and value.
$field_key = 'field_53ef95cead820';
$value = get_field($field_key, $postID);
foreach($specs as $spec):
$specArray = explode(':',$spec);
if($specArray[0] && $specArray[1]):
$value[] = array("label" => $specArray[0], "value" => $specArray[1]);
endif;
++$i;
endforeach;
update_field( $field_key, $value, $postID );
To modify the associated parts field, should I set it up as a repeater like this and then create some sort of array to populate it, or should I use the multi select option and still pass some sort of an array to it. I'm happy to go either route, I just need some way to get those fields in there.
It's impossible to add associate products (other posts) during the initial import due to the fact that while you are importing the first product into WordPress, it's associated parts have not yet been created. For this reason I had to run two imports of the spreadsheet into WordPress.
On the first import, it created all the posts and added all of the non-relational custom fields as they appeared in the spreadsheet. I setup the script the print the post ID's of the imported products in a table format that allowed me to easily copy and paste all of the ID's at once from the script output back into a "Product ID" field in the spreadsheet. The script checks for the existence of a product ID and this field is what will determine if it is creating a new post/product or updating an existing one.
Once all the products had been imported and their respect ID's were added to the spreadsheet, we began the second import. We used the exact same spreadsheet with the only difference being that now it had the WordPress ID's added to a column.
1. if($product['Associated Parts']):
2. $assParts = explode('|',$product['Associated Parts']);
3. unset($assIDs);
4. foreach($assParts as $assPart):
5. unset($assID);
6. if($assPart):
7. $assID = get_page_by_title( $assPart , 'OBJECT' , 'product' );
8. $assIDs[] = $assID->ID;
9. endif;
10. endforeach;
11. $assIDs = array_filter($assIDs);
12. update_field( 'field_542c5dc44272e' , $assIDs , $product['Page ID'] );
13. endif;
Breakdown of the code line by line:
I check to see if this product has any associated parts assigned to it.
I convert the pipe separated list of associated parts into an array.
I unset the array that we will be using to store the array of post ID's. I do this so that the associated parts from the first product are not still stored in the array when we begin processing the second product.
I begin looping through the array of associated parts. Each item in this array contains the title of the associated part. In order for this to work, the titles must be spelled, formatted and in all other ways identical to the title of the WordPress post.
Same as 3, only now it's for this particular associated part.
This line was added to ensure that I wasn't searching for an associated part if that item of the array was an empty string.
I retrieve the WordPress post item that matches the title of this particular associated item.
I add the ID of the associated product to a numeric array.
Close the if statement on line 6.
End the associated products loop.
Filter out any empty strings or null values from our array of post ID's.
We pass the the numeric array containing the post ID's into the Advanced Custom Fields "update_field()" function. The first parameter is the unique field key of the Post Object custom field. The second parameter is the array of associated products ID's. The third parameter is the ID of the product we are editing.
Close the if statement on line 1.
I had to guess as to the format I needed to use for the value of the field. At first, I tried passing in an array of Post Objects and that didn't work. In the WordPress post editor, I inspected the code and saw that the value of their input field (when another post was selected) was that posts ID. After switching to a numeric array containing the Posts' ID's, the update_field() function accepted them perfectly without incident.
We're done.
I can't seem to find any way to do this:
Users can check "styles" for certain music in a form name="style[]", which creates an array: $styles=$_POST['style'; using php. I implode the string and store it as a comma-delimited string in a database VARCHAR field, with the artists name, address, phone and other info.
Another user, using a form checkbox to show list of artists that have certain styles (ie,"blues", "jazz", and "folk") name="filter[]" which creates another array when the form is submitted $filters = $_POST['filter']
Now I want to pull from the artists table (via mysql_query) those artist who have a the comma-delimited string stored in the field "styles" $info['styles'] and display the artist info that match any one or more of those elements in the array $filters.
Any help would be appreciated.