0

I have a preg_match command ;

<?php
    $content = "<span class='hotels'><div id='general_parcel_id'></div></span>";
    $wanted=preg_match ('/<span class=\'hotels\'>(.*?)<\/span>/', $content, $result);
    $resultant = $result[1];
?>

Note : <div id='general_parcel_id'></div> prints an id for each product on the page.

and finally I want to use this $resultant variable, for a database connection.

Ex.

$dbase = mysql_fetch_array(mysql_query("select * from hotex WHERE parcel_id = '$resultant'"));

but this is not possible. Write the result as variable once. Only once

Thank you in advance ...

Clément Malet
  • 5,062
  • 3
  • 29
  • 48
Extropy
  • 13
  • 1
  • 1
  • 5
  • Please can you paste your whole script, or at least everything between the 1st and 2nd sections. PHP will not unset variables but you might have a scoping issue or be accidentally reassigning it yourself. Also, what is the output of `echo $resultant;` – M1ke Jan 27 '15 at 12:02
  • You shouldn't use regular expressions to parse HTML... Read more [here](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – Michel Tomé Jan 27 '15 at 13:01
  • @M1ke This is the entire script. There's nothing between the two. Output of echo $ resultant = variable of the product on the page (Ex: 162, 163, 164, etc.) different on each page. – Extropy Jan 27 '15 at 16:03
  • @M1ke 'echo $resultant' gives me results. But, can not be assigned to a variable in the database connection. – Extropy Jan 27 '15 at 16:08
  • @Pete does not preg_match_all – Extropy Jan 27 '15 at 16:16
  • Add to your original post: output of `echo $resultant;` and then output of `echo "select * from hotex WHERE parcel_id = '$resultant'";` – M1ke Jan 27 '15 at 16:20
  • Essentially there is no reason that a variable will be set in one line and not in the next. So either the variable is set and something else is wrong, or there's code in between those lines. – M1ke Jan 27 '15 at 16:22
  • Dear @M1ke this is a variable. For example, a page : `echo $resultant;` = **162** `echo "select * from hotex WHERE parcel_id = '$resultant'";` = **162 = 162** `echo
    ` = **162** . Another to another page. Ex **163**
    – Extropy Jan 27 '15 at 16:31
  • @M1ke So my problem Assign this div value ( `
    ` ) to $resultant variable. Like this `<$resultant =
    `
    – Extropy Jan 27 '15 at 17:14
  • Those aren't the outputs of the `echo` commands. I'm asking to help debug your code because your problem isn't clear; add those `echo` lines into your code and add the output to your question. – M1ke Jan 28 '15 at 15:10

0 Answers0