Đang Thực Hiện

Fix search function using php on Wordpress blog

I have a Wordpress website/blog here: [url removed, login to view]

I am trying to set up a way to search a database. See the “Carb Database” page.

When a food is input, and “Search” is pressed, I want to execute the php code below.

The database is not part of the Wordpress site but is hosted on the same server.

I can send you the database.

"Mcarbs",

"Fiber" => "Mfiber",

"Sugar" => "Msugar",

"Sodium" => "Msodium",

"Saturated Fat" => "Msatfat",

"Total Fat" => "Mlipid",

"Cholesterol" => "Mchol");

// Get the search variable from URL

$var = @$_GET['q'];

//trim whitespace from the stored variable

$trimmed = trim($var);

// rows to return

$limit = 1000;

// check for a search parameter

if (strlen($trimmed) == 0 || strlen($var) == 0) {

// echo "We don't seem to have a search parameter!";

exit;

}

//connect to your database

mysql_connect("localhost", "***", "***") or die("Unable to connect to database"); // host, username, password

mysql_select_db("***") or die("Unable to select database"); // database

//specify database

// DEPRECATED mysql_select_db("carbs") or die("Unable to select database");

// Build SQL Query

$query = "SELECT * FROM `carbs` WHERE `Desc` LIKE '%" . mysql_real_escape_string($trimmed) . "%' ";

// $query = "select * from carbs where Desc like "%$trimmed%"";

// $numresults = $query->num_rows();

// $numresults=mysql_query($query);

// $numrows=mysql_num_rows($numresults);

// $numrows = $query->num_rows(); ????

// next determine if s has been passed to script, if not use 0

if (empty($s)) {

$s = 0;

}

// get results

$query .= " LIMIT $s,$limit";

$result = mysql_query($query) or die("Couldn't execute query");

// $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for

echo "You searched for: \"" . strip_tags($var) . "\"";

echo "Results by food and serving sizes. "[No data]" means information not in database. Unless otherwise specified, results are in grams of carbs which is what we use to count our [url removed, login to view] Results KeyCarbs: Total carbsFiber: Total fiberSugar: How many of the total carbs are simple carbsSodium: Milligrams of saltSaturated fat: How much bad fatTotal fat: Good and bad fat combinedCholesterol: Milligrams of cholesterol";

$count = 1 + $s ;

// now you can display the results returned

while ($row = mysql_fetch_array($result)) {

// $food = $row["Desc"];

// $calories = $row["Energy_Kcal"];

// $protein = $row["Protein_(g)"];

echo "";

$count++ ;

echo "" . $row["Desc"] . " ";

echo "Serving size 1: " . $row["GmWt_Desc1"] . ": ";

foreach ($carbs_1 as $key => $value) {

echo $key . ": " . $row[$value . "1"] . ", ";

}

echo "";

echo "Serving size 2: " . $row["GmWt_Desc2"] . ": ";

foreach ($carbs_1 as $key => $value) {

echo $key . ": " . $row[$value . "2"] . ", ";

}

}

echo "";

$currPage = (($s/$limit) + 1);

//break before paging

echo "";

// next we need to do the links to other results

if ($s >= 1) { // bypass PREV link if s is 0

$prevs = ($s-$limit);

print " <

Please provide me with files/instructions. Thank you.

Kỹ năng: MySQL, PHP, WordPress

Xem thêm: we trying to function, unable to connect to website fix, protein simple, php com wordpress, how to set up a blog, how do you set up a blog site, how do i set up a blog, get your website on wordpress, fix your website now, where can i get a blog, password break, how do i get a wordpress website, deprecated, build website on wordpress, wordpress query search, size function, wordpress fix database password, php script execute, php simple username password script, deprecated code, sql stored function, wordpress print query sql, check input function php, function check php, wordpress query script

Về Bên Thuê:
( 51 nhận xét ) Dallas, United States

Mã Dự Án: #4539595