PHP array\string refresher for an old-timer


After around 20 years of not working with PHP\MySQL, it appears I am in need of a little assistance (as I have forgotten most of what I knew) to point me in the proper direction.


What I have is a basic search field that automatically pulls information from MySQL once the user enters a couple of letters in the field. The data is quiered against certain colums in the database table (in this case it pulls from the name, street and city). For instance if a user enters "bad" it displays 2 venues that have "bad" in the name and echos the pertinent information below the search field. When the user adds an additional "a" at the end of "bad" one of the venues goes away leaving only 1 behind. The echoed information has hyperlinked venue names which leads me into what I need it to do (and where I am stumped).


What I require is when a user clicks on the hyper-linked venue name, the data for that venue is displayed in a new page. The data fields would be: name, address, city, website, email, info, event, categories and their logo (which is stored in the database as a BLOB). Yes, I know that it's quicker to reference to the logo file in the database and keep the image as a file in a directory, but that's not how the person wants it done not to mention the logo files are quite small (~60k each).


Below is the search code with the data ID echoing back for my own reference until it is no longer required to echo back. What I do know is the information will need to be placed into arrays and then read from the arrays utilizing the DB table ID. Which is where I find myself running in circles for such a basic (and archaeic) task.



```
<?php


include_once ('mdbconn.php');

if(isset($_GET['keyword'])){
    $keyword =  trim($_GET['keyword']) ;
$keyword = mysqli_real_escape_string($dbc, $keyword);



$query = "select id,venue,category,city,address,info,event from buffnoa where venue like '%$keyword%' or category like '%$keyword%' or address like '%$keyword%' or city like '%$keyword%'";

//echo $query;
$result = mysqli_query($dbc,$query);
if($result){
    if(mysqli_affected_rows($dbc)!=0){
          while($r = mysqli_fetch_array($result,MYSQLI_ASSOC)){
     echo '<p>' .$r['id'].' <b><a href>'.$r['venue'].'</a></b> '.$r['address'].' </br>'.$r['city'].'</p>' ;
    }
    }else {
        echo 'No Results for :"'.$_GET['keyword'].'"';
    }

}
}else {
    echo 'Parameter Missing';
}




?>

```
use the query string to pass the venue id to the generic venue display page, make your <a> tags ref that page with "?id=xxx" at the end, from the venue page fetch that xxx value and query your db for that specific venue, and display that venue's fields as you like.


$myvar = $\_GET['id']; and thus  

Select * FROM table WHERE field='$myvar'
First you need to clear the call in the database. `$mysqli->query`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

sent request before parameter binding, etc.


Replace as follows:



```
$stmt = $mysqli->prepare('SELECT reply\_id FROM replies WHERE reply\_topic = ? ORDER BY reply\_date ASC');
$stmt->bind_param('i',$param)
$stmt->execute();

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

 `$mysqli->prepare`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

returns a new object for which you want to bind values ​​and execute them. It avoids [SQL injection](https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=) !


None of this is discounted. `mysqli_`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

is exactly what you should be using.



  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

Since all you need is an array of results, you can use the following code to do this - no custom functions are required.



```
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
        $set[] = $row['reply\_id'];
}

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

For each row, `while`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

each field is stored in an array with the column name as the key. Thus, `$row['reply_id']`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

contains the value of a column `reply_id`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

in the database. Above, I have stored this value in a named array `$set`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

and when it iterates over the next row of the result, it also stores the next value for that array.


You can manipulate the result before or after saving it to a new array as you see fit.


Hope it helps. A few things to try.


1. Use [Variable Tables](http://odetocode.com/Articles/365.aspx) instead -> maybe the import wizard prefers that?
2. Name your return fields.


Try using the following stored proc (untested .. just thinking out loud...)



```
CREATE PROCEDURE dbo.Foo
AS

    SET NOCOUNT ON

    DECLARE @ResultTable TABLE (SomeId INTEGER)

    INSERT INTO @ResultTable
    SELECT DISTINCT Id AS Identity -- Or u can rename this field to anything...
    FROM SomeExistingTableWhichHasAnIdentityField

GO

```

Try that and see if the wizard refreshes, now.


-- 


 Attempt #2 :)


Ok .. when the EF designer/wizard/whatever fails to figure out EXACTLY what my stored proc is suppose to be returning, I usually do the following :-


1. Make sure the stored procedure doesn't exist at all in the EF designer/context, etc. (You have a clean starting point)
2. Open up your stored procedure and `/* /*` comment out *EVERYTHING* after the procedure definition.


eg..



```
ALTER PROCEDURE dbo.Foo
(
    Bar1 INT,
    Bar2 TINYINT,
    ... // whatever u have as your optional input arguments //
)
AS
    SET NOCOUNT ON

    /* 
    .... every thing in here is commented out 
    */
GO

```

Now ...
 3. Add a forced fake return in the stored proc, which (more or less) just *defines* the output structure/fields.


eg..



```
ALTER PROCEDURE dbo.Foo
(
    Bar1 INT,
    Bar2 TINYINT,
    ... // whatever u have as your optional input arguments //
)
AS
    SET NOCOUNT ON

    SELECT 1 AS Id, 1 AS UserId, 1 AS SomeOtherId, 
        CAST('AAA' AS NVARCHAR(350)) AS Name,
        -- etc etc etc..
    /* 
    .... every thing in here is commented out 
    */
GO

```

[and then](http://www.youtube.com/watch?v=K7luMp6lb9M) ...


4. Add this stored proc to your EF designer/wizard/etc... Now the correct fields should be 'determined' by the designer. AWESOME. Yes .. the values are all hardcoded .. but that's ok (so far).
5. Once your happy that EF is now updated right, go back to your stored proc, and remove all hardcoded SELECT (which we did in the above step). Now we remove the comments which we commented out the entire real code. So you should have your original stored proc, back.


... and now EF is updated and doesn't know we've changed the plumbing of your stored proc.


win :)


does this work for ya? 1) Usage `yii`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

and `php yii`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

exactly the same. If you look at the file `yii`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

, you'll see it in the first line `#!/usr/bin/env php`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. This is called the "shebang" syntax and instructs your shell to automatically execute the `yii`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

script using binary code `php`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. See: [https://en.wikipedia.org/wiki/Shebang\_%28Unix%29](https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=)


2) The difference here is flexibility. If you use the syntax `Schema::TYPE_PK`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

, Yii will automatically detect the exact column type based on your database database. For example, it `Schema::TYPE_PK`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

translates to `int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

in MySQL, but if you use Postgres as your database, it will translate to `serial NOT NULL PRIMARY KEY`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. [1]



  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

In practice, it is unlikely which method you are using because you are probably not going to switch to a different type of database halfway through your project, and therefore there is no need for your migration scripts to be database agnostic. Based on your preference, you can choose the syntax `Schema`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

for added flexibility, or for a hard-coded syntax to make your hyphenation definitions more readable for future readers.


[1] See [https://github.com/yiisoft/yii2/blob/master/framework/db/pgsql/QueryBuilder.php#L21](https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=) and [https://github.com/yiisoft/yii2/blob/master/framework /db/mysql/QueryBuilder.php#L24](https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=) JavaScript *itself* has nothing built in for handling query string parameters. 


Code running in a (modern) browser you can use the [`URL` object](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) (which is part of the APIs provided by browsers to JS):





```
var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
```









For older browsers (including Internet Explorer), you can use [this polyfill](https://github.com/ungap/url-search-params) or the code from the original version of this answer that predates `URL`:


You could access `location.search`, which would give you from the `?` character on to the end of the URL or the start of the fragment identifier (#foo), whichever comes first.


Then you can parse it with this:





```
function parse_query_string(query) {
  var vars = query.split("&");
  var query_string = {};
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    var key = decodeURIComponent(pair[0]);
    var value = decodeURIComponent(pair[1]);
    // If first entry with this name
    if (typeof query_string[key]  "undefined") {
      query_string[key] = decodeURIComponent(value);
      // If second entry with this name
    } else if (typeof query_string[key]  "string") {
      var arr = [query_string[key], decodeURIComponent(value)];
      query_string[key] = arr;
      // If third or later entry with this name
    } else {
      query_string[key].push(decodeURIComponent(value));
    }
  }
  return query_string;
}

var query_string = "a=1&b=3&c=m2-m3-m4-m5";
var parsed_qs = parse_query_string(query_string);
console.log(parsed_qs.c);
```




You can get the query string from the URL of the current page with:



```
var query = window.location.search.substring(1);
var qs = parse_query_string(query);

``` <p>i think that the crawler understand well the keyword madrid in the domain madridlive, for this you can avoid the repeat another time rhe same word.</p>
<p>&nbsp;</p>
<p>www.madridlive.com/restaurant/great-food</p>
<p>&nbsp;</p>
<p>for me is also better.</p>
<p>&nbsp;</p>
<p>ciao</p>
<p>maurizio</p> hello, the easiest way to fix that would be to alter your existing user with the following: alter user myuser identified with mysql\_native\_password by 'mypassword'; another thing that you could do is to create a new user with mysql\_native\_password. to do that you could use the following: create user 'your\_user'@'your\_server\_ip ' identified with mysql\_native\_password by 'your\_password'; also as mentioned by @kavo13, try to upgrade php to 7.2 as well. after that, it should all work as normal. i’ve created a quick video demo on how to do that: i’m running the test on an ubuntu 18.04 droplet. hope that this helps! regards, bobby you would need something like this then pull a list of people in that database after the ammount of time 
 /**
 * @event discordmessagereaction
 */
 $.bind('discordmessagereaction', function (event) {
 var reactionevent = event.getevent(),
 reactionuser = reactioneve… I'm not sure where it comes from `vlist`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. It should probably be part of the user state of the parser. For now, let's assume this is the top-level definition:



```
vlist :: [(String, Float)]
vlist = undefined -- fill in the blanks...

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

I assume you are using `Parsec`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. You can simplify your parser:



```
primary :: Parser Float
primary = choice [ between (symbol "(") (symbol ")") expression
                 , do { ident <- identifier
                      ; case lookup ident vlist of
                          Nothing -> fail $ "No such identifier: " ++ ident
                          Just v -> return v
                      }
                 ]

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```


  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

You have several options for solving this problem. Here I used the parader monad function `fail`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. This will cause the parser to return a value `Left parserError`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. Alternatively, you can replace `error`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

with `fail`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

, which will result in an error that can only be handled in a monad `IO`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

.


 **Note** . To add `vlist`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

a parser as a state, you need to define a new parser type with this state:



```
data MyParserState = MyParserState { vlist :: [(String, Float)] }
type MyParser = CharParser MyParserState

-- these parsers now need to return MyParser type!
symbol :: String -> MyParser String
identifier :: MyParser String
expression :: MyParser Float

primary :: MyParser Float
primary = choice [ between (symbol "(") (symbol ")") expression
                 , do { st <- getState
                      ; ident <- identifier
                      ; case lookup ident $ vlist st of
                          Nothing -> fail $ "No such identifier: " ++ ident
                          Just v -> return v
                      }
                 ]

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
``` hi chris, 
if you use relations api, you may set properties field in your query. in this field you should set the names of the properties which values must be retrieved from the server. the argument should be a string in the following format: "propertyname1, propertyname2, , , propertynamen" , wher… try a quick search on google with your key words.