Customizing SMF > SMF Coding Discussion

First time using database entries, need help calling out a row.

<< < (2/4) > >>

live627:
Are there any errors in the log related to this? Try surrounding that variable with apostrophes.

CapadY:

--- Quote from: Liam_michael on June 28, 2012, 10:02:30 PM ---Thanks live627,

I tried this exact thing:


--- Code: ---$dbresult = db_query("
SELECT
si_title, si_page
FROM smf1searchindex
WHERE si_title = $deftitle
ORDER BY si_page DESC
LIMIT 1", __FILE__, __LINE__);
list ($si_title, $si_page) = mysql_fetch_row($dbresult);
mysql_free_result($dbresult);

echo '',$si_title,';
--- End code ---

I didn't get an output, just blank.

I think it has to do with $deftitle


--- Code: ---WHERE si_title = $deftitle
--- End code ---

Should that even be there? I just put that there for fun.

What am I doing wrong still?

--- End quote ---

You will only have a result if there is a record with $deftitle as content for the title field. And then I mean literly that as content.

I suspect you want to use the content of the variable $deftitle, in that case your query is wrong.

It should be something like this:


--- Code: ---$dbresult = db_query("
SELECT
si_title, si_page
FROM smf1searchindex
WHERE si_title = \"".$deftitle."/"
ORDER BY si_page DESC
LIMIT 1", __FILE__, __LINE__);
list ($si_title, $si_page) = mysql_fetch_row($dbresult);
mysql_free_result($dbresult);

echo '',$si_title,';

--- End code ---

emanuele:

--- Code: ---echo $si_title;
--- End code ---

Liam_michael:
Why do we add:

WHERE si_title = \"".$deftitle."/"

$deftitle isn't even defined anywhere.

live627:
Then you can delete the entire line.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version