Reputation: 67
I have a table in mysql that contain two columns or fields, one column is for an id_column
and others for description
of string type. I would like to insert an specific string to the column description
.
For example:
insert into table_name (id, description) values ('1','we go to school')
And then in my php file, I would like to fetch the specific word "school" from the column description
.
How can I do this?
Upvotes: 0
Views: 338
Reputation: 1523
You'll be needing to use SQL Wildcard Characters
So your query can be something like:
select * from tabel where description like '%school%';
EDIT :
I guess you need to get description first then according to it you want to manage the output.
For that try this :
$sqldata= mysqli_query('select * from tabel)';
$rowcount=mysqli_num_rows($sqldata);
if($rowcount > 0)
{
while($result = mysqli_fetch_assoc($sqldata)) // fetch records
{
$description = $result['desription'];
$id = $result['id'];
}
}
Upvotes: 0
Reputation: 332
I'm not really understand what you want. But I guess, you want to get image source from the description column.
$q = mysql_query("select id, description from tabel");
$row = mysql_fetch_assoc($q);
$html = $row["description"];
preg_match( '@src="([^"]+)"@', $html, $match );
$src = array_pop($match);
echo $src;
Upvotes: 0
Reputation: 133370
You can use like with wildchar .
select * from your_table
where description like '%school%';
in php for find if a string contain a word you can use
$my_string = 'we go to school';
if (strpos($my_strong, 'school') !== false) {
echo 'string found';
}
Upvotes: 1