Related
What I want to do is When I enter all my information (for client ID 199 in the picture) In my account being submit it, it goes into the database. BUT I want it to change to something and so i added an if statement
Here the code im adding to the existing code already at the BOTTOM of the code
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
if the ($vpr_clid = 199)
i want the clname to be "Shelley Madsen And Associates" then what is show in the table below instead of "Nice and White Smiles" (that an example of the results look like)
but when i chcek the database it not changing it and still show "Nice and White Smiles :(
I dont see any error, so it might be the placement of the code i have to put the IF statement in the huge php file? Dont know how to fix this issue
Thanks (the code below is the base code before i added the If statement)
I also insert the if statement before the function were called but still didnt work example
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
<?php
session_start();
if ($_SESSION['company'] != "ACB") {
// redirect to the logout page
$redirect = 'logout.php';
include './includes/redirect.php';
}
class variables_obj {
var $vpr_plan = '';
var $vpr_id = '';
var $vpr_clid = '';
var $vpr_cl_name = '';
var $vpr_cl_phone = '';
var $vpr_call_start_date = '';
var $vpr_db_account = '';
var $vpr_db_fname = '';
var $vpr_db_mname = '';
var $vpr_db_lname = '';
var $vpr_rp_fname = '';
var $vpr_rp_mname = '';
var $vpr_rp_lname = '';
var $vpr_rp_address = '';
var $vpr_rp_city = '';
var $vpr_rp_state = '';
var $vpr_rp_zipcode = '';
var $vpr_rp_phonenum = '';
var $vpr_rp_phonetype = '';
var $vpr_date_entered = '';
var $newrecdt = '';
var $vpl_day_offset = '';
var $vpl_action = '';
var $vpr_promocode = '';
}
function ScrubPhone($old_phone_num) {
$phone_length = strlen($old_phone_num);
$new_phone_num = "";
for($i = 0; $i < $phone_length; $i = $i + 1) {
if(is_numeric($old_phone_num[$i])) {
$new_phone_num .= $old_phone_num[$i];
}
}
return $new_phone_num;
}
function ScheduleCreated($link, $vars) {
$query = "UPDATE v_payreminder SET vpr_schedule_created = '1' WHERE vpr_id='".$vars->vpr_id."'";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateScheduleRow($link, $vars){
// echo "vpl_day_offset: ".$vars->vpl_day_offset."<br>";
// echo "vpl_action: ".$vars->vpl_action."<br>";
$plus_days = " +".$vars->vpl_day_offset." days";
// echo "plus days: ".$plus_days."<br>";
$date_offset = strtotime(date("Y-m-d", strtotime($vars->vpr_date_entered)).$plus_days);
$date_offset = date("Y-m-d", $date_offset);
// echo "date_offset: ".$date_offset."<br>";
// $date_offset = strtotime(date("Y-m-d",strtotime($vars->vpr_date_entered))." +".$vars->vpl_day_offset." days");
// $date_offset = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
// echo "date_offset: ".$date_offset."<br>";
$query = "INSERT INTO v_pr_schedule (
vpr_id,
vsc_plan,
vsc_date_entered,
vsc_action,
vsc_action_date,
vsc_status
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'$vars->vpl_action',
'$date_offset',
'VACT')";
//echo "query: ".$query."<br>";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateSchedule($link, &$vars) {
// CREATE SCHEDULE
$query = " SELECT vpl_day_offset, vpl_action, vpl_condition
FROM v_plan
WHERE vpl_plan = '".$vars->vpr_plan."'";
// echo "query: ".$query."<br>";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
while ($row = mysql_fetch_array($qresult, MYSQL_ASSOC)) {
$vars->vpl_day_offset = $row['vpl_day_offset'];
$vars->vpl_action = $row['vpl_action'];
if ($row['vpl_condition'] == 'OO') {
CreateScheduleRow($link, $vars);
}
}
}
return true;
}
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
//echo "Client Name: ".$vars->vpr_cl_name."<br><br>";
//exit();
$sql="INSERT INTO v_payreminder (
vpr_clid,
vpr_cl_name,
vpr_cl_phone,
vpr_call_start_date,
vpr_db_account,
vpr_db_fname,
vpr_db_mname,
vpr_db_lname,
vpr_rp_fname,
vpr_rp_mname,
vpr_rp_lname,
vpr_rp_phonenum,
vpr_rp_phonetype,
vpr_rp_address,
vpr_rp_city,
vpr_rp_state,
vpr_rp_zipcode,
vpr_promo,
vpr_date_entered) VALUES (
'$vars->vpr_clid',
'$vars->vpr_cl_name',
'$vars->vpr_cl_phone',
'$vars->vpr_call_start_date',
'$vars->vpr_db_account',
'$vars->vpr_db_fname',
'$vars->vpr_db_mname',
'$vars->vpr_db_lname',
'$vars->vpr_rp_fname',
'$vars->vpr_rp_mname',
'$vars->vpr_rp_lname',
'$vars->vpr_rp_phonenum',
'$vars->vpr_rp_phonetype',
'$vars->vpr_rp_address',
'$vars->vpr_rp_city',
'$vars->vpr_rp_state',
'$vars->vpr_rp_zipcode',
'$vars->vpr_promocode',
'$vars->vpr_date_entered')";
if (!mysql_query($sql,$link)) {
die('Error2: ' . mysql_error());
}
return true;
}
function GetVpr_Id($link, &$vars) {
// Find out what vpr_id is
$query = "SELECT vpr_id FROM v_payreminder ";
$query .= "WHERE vpr_clid = '".$vars->vpr_clid."' AND vpr_date_entered = '".$vars->vpr_date_entered."'";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
$row = mysql_fetch_array($qresult, MYSQL_ASSOC);
$vars->vpr_id = $row['vpr_id'];
}
}
function InsertInActivity($link, $vars) {
// ENTER INTO ACTIVITY
$vaction_desc = 'PATIENT ENTERED';
$sql = "INSERT INTO v_pr_activity (
vpr_id,
va_plan,
va_action_dttm,
va_action_code,
va_action_desc,
va_disposition_code,
va_disposition_desc,
va_status_code,
va_status_desc
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'VINIT',
'$vaction_desc',
'SUCCESS',
'SUCCESS',
'VACT',
'ACTIVE'
)";
if (!mysql_query($sql,$link)) {
die('Error: ' . mysql_error());
}
}
include './includes/dblogin.php';
$vars = new variables_obj();
$vars->vpr_plan = 'VP01';
$vars->vpr_clid = $_SESSION['userid'];
//-------------------------------------------------------
// No commas can be in client name or they will
// mess up the Global Connect CSV file.
//-------------------------------------------------------
$vpr_cl_name = $_SESSION['username'];
$vpr_cl_name = str_replace(",", " ", $vpr_cl_name);
$vars->vpr_cl_name = $vpr_cl_name;
//-------------------------------------------------------
//-------------------------------------------------------
$vars->vpr_cl_phone = ScrubPhone($_SESSION['uphone']);
$vars->vpr_call_start_date = '0000-00-00';
$vars->vpr_db_account = $_POST['ndaccnum'];
$vars->vpr_db_fname = $_POST['ndfreqname'];
$vars->vpr_db_mname = $_POST['ndmname'];
$vars->vpr_db_lname = $_POST['ndlreqname'];
$vars->vpr_rp_fname = $_POST['ndrfreqname'];
$vars->vpr_rp_mname = $_POST['ndrmname'];
$vars->vpr_rp_lname = $_POST['ndrlreqname'];
$vars->vpr_rp_address = '';
$vars->vpr_rp_city = '';
$vars->vpr_rp_state = $_POST['ndrstatereqname'];
$vars->vpr_rp_zipcode = $_POST['ndrreqzipcode'];
$phonenumber = $_POST['1ndrreqphone'].$_POST['2ndrreqphone'].$_POST['3ndrreqphone'];
$vars->vpr_rp_phonenum = $phonenumber;
$vars->vpr_rp_phonetype = $_POST['treqphone'];
$vars->vpr_date_entered = date('Y-m-d H:i:s');
$vars->newrecdt = date('Ymd');
$vars->vpr_promocode = $_POST['promocode'];
// echo "vpr_plan: ".$vars->vpr_plan."<br>";
// echo "vpr_date_entered: ".$vars->vpr_date_entered."<br>";
// echo "newrecdt: ".$vars->newrecdt."<br>";
// echo "vpr_clid: ".$vars->vpr_clid."<br>";
// echo "vpr_id: ".$vars->vpr_id."<br>";
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
$result = InsertInActivity($link, $vars);
$result = CreateSchedule($link, $vars);
$result = ScheduleCreated($link, $vars);
// echo "vpr_id: ".$vars->vpr_id."<br>";
mysql_close($link);
// redirect
$redirect = 'vpayremind.php';
include './includes/redirect.php';
?>
okay referencing the following lines..
if ( $vpr_clid == 199 ) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
...and then:
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
so on and so forth... }
it doesnt seem as if you are actually setting the value of the class object. You seem to be setting some arbitrary php variable to the name you want, and then passing a totally different ' $vars ' object into the function. I don't see any reason to believe that the ' $vars ' you are passing into the function call contains the name value you want it to contain. You should be assigning the value of ' $vars ' before passing it in.
For instance:
if ( $vpr_clid == 199 ) {
$vars[ 'vpr_cl_name' ] = "Shelley Madsen And Associates";
}
then you can get rid of this line all together:
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
I have some if statements in my code.
e.g:
if($option[0]->posts == 1 && $option[0]->pages == 1){
$results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'posts WHERE post_status="publish" AND (post_type="page" OR post_type="post") ORDER BY post_title ASC', OBJECT );
}
if($option[0]->pages == 1 && $option[0]->posts == 0){
$results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'posts WHERE post_status="publish" AND post_type="page" ORDER BY post_title ASC', OBJECT );
}
if($option[0]->pages == 0 && $option[0]->posts == 1){
$results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'posts WHERE post_status="publish" AND post_type="post" ORDER BY post_title ASC', OBJECT );
}
a bit pseudo code of the code above:
if foo = 1 and bar = 1 -> return foo and bar
if foo = 0 and bar = 1 -> return only bar
if foo = 1 and bar = 0 -> return only foo
if foo = 0 and bar = 0 -> return false
You see:
00
10
01
11
00
If I insert another variable I'll get a lot of more opportunities and that is realy bad. Because I'll get realy big if statements.
Can somebody tells me another opportunitie to achive the same result?
Thank you.
I'd do it like this:
$sql_condition = '( 1=2 '; // one fake-condition, just to make it possible to start with 'OR' later
foreach($option[0] as $key => $value) { // iterate through all possible conditions
if($value===1) { // maybe exclude $keys that should not be used here
$sql_condition.=' OR post_type="'.$key.'"';
}
}
$sql_condition.=')';
$results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'posts WHERE post_status="publish" AND '.$sql_condition.' ORDER BY post_title ASC', OBJECT );
Please try this code :
$sub_query = $operator = '';
if($option[0]->posts == 1)
{
$sub_query = 'post_type="page"';
$operator = ' OR';
}
if($option[0]->pages == 1)
{
$sub_query .= $operator.' post_type="post"';
}
if(empty($sub_query))
{
return false;
}
else
{
$results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'posts WHERE post_status="publish" AND ('.$sub_query.') ORDER BY post_title ASC', OBJECT );
}
Create an array($arr) and set the key like "0,0" and value like "$sql";
and your code will be like this:
$tempKey = $option[0]->pages . "," . $option[0]->posts;
if(isset($arr[$tempKey]) {
$results = $wpdb->get_results($arr[$tempKey]);
}
So when you want to add more pages and posts all you will do is to change the arr.
$types = [];
if ($option[0]->posts)
$types[] = '"post"';
if ($option[0]->pages)
$types[] = '"page"';
if (!$types)
return null;
$results = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'posts WHERE post_status="publish" AND (post_type IN ('. implode(',', $types) .')) ORDER BY post_title ASC', OBJECT );
I recently migrated a PHP site to my server and after migration I receive this error message. As I'm not really familiar with PHP, I'd really appreciate any help. Thanks.
Warning: strpos() expects parameter 1 to be string, resource given in
.../public_html/store /product_list.php on line 121
Line 121 is as follows...
$exists = (strpos($handle, "Resource id") !== false) ? true : false;
Here is the rest of the code on the top of the page for relevance.
<?php session_start();
include_once("../includes/define.inc.php");
include("../includes/common.php");
include("../includes/mysql_functions.php");
if( isset( $_GET['category'] ) )
{
$exists = checkIfExists("aw_category", "aw_category_urlalias='". $_GET['category']."'", "aw_category_id");
if( !$exists )
{
header("Location: " . PRODUCT_LIST );
}
}
$get_category = ( isset( $_GET['category'] ) ) ? $_GET['category'] : "";
$category_id = ( $get_category == "" ) ? "" : getCategoryIDByAlias( $get_category );
$get_page = (isset($_GET['page']) ) ? $_GET['page'] : 0;
/*category menu*/
$qry_cat = "SELECT aw_category_urlalias, aw_category_id,aw_category_name,aw_category_order,aw_category_status FROM aw_category WHERE aw_category_status = 1 ORDER BY aw_category_order asc";
$result_cat = Query($qry_cat);
/*product*/
$qry_pro = "SELECT *
FROM aw_product
INNER JOIN aw_category
ON aw_product.aw_product_category = aw_category.aw_category_id
INNER JOIN aw_image
ON aw_product.aw_product_id = aw_image.aw_img_prodid
WHERE aw_product.aw_product_status = 1";
if( $category_id == "" )
{ //Feature Product
$qry_pro .= " AND aw_product.aw_product_category = 1";
} else {
$qry_pro .= " AND aw_product.aw_product_category = ".$category_id."";
}
$qry_pro .= " GROUP BY aw_product.aw_product_id
ORDER BY aw_product.aw_product_priority desc,aw_product.aw_product_date desc";
if( $get_category=="" )
{ //Feature Product
$qry_pro .= " LIMIT 6";
}
$result_pro = Query( $qry_pro );
//$row_pro = mysql_fetch_array($result_pro);
$result_pro2 = Query( $qry_pro );
if( !$get_category == "" )
{
/*Pagination*/
$num_per_page= 12;
$num_rows = mysql_num_rows($result_pro);
$num_pages = ceil($num_rows/$num_per_page);
$nav = "";
$begin = $get_page * $num_per_page;
$qry_pro .= " LIMIT " . $begin . ",12";
$result_pro = Query( $qry_pro );
$row_pro = mysql_fetch_array($result_pro);
if( $get_page > 0 )
{
$nav ="<a class=\"page_a\" href=\"".PRODUCT_LIST."?category=".$get_category."&page=".( $get_page-1 )."\">« Previous</a> | ";
}
for($p=0;$p<$num_pages;$p++)
{
if($get_page == $p)
$nav .="<a class=\"page_a\" style='text-decoration:underline' href=\"".PRODUCT_LIST."?category=".$get_category."&page=".$p."\">".($p+1)."</a> | ";
else
$nav .="<a class=\"page_a\" href=\"".PRODUCT_LIST."?category=".$get_category."&page=".$p."\">".($p+1)."</a> | ";
}
if($get_page<$num_pages-1)
{
$nav .="<a class=\"page_a\" href=\"".PRODUCT_LIST."?category=".$get_category."&page=".($get_page+1)."\"> Next »</a>";
}
}//-------
/*news*/
$qry_news = "SELECT aw_news_title FROM aw_news ORDER BY aw_news_date desc LIMIT 8";
$result_news = Query($qry_news);
function getCategoryIDByAlias( $alias )
{
$query = "SELECT aw_category_id FROM aw_category WHERE aw_category_urlalias='".$alias."'";
$rs = Query( $query );
$row = mysql_fetch_array( $rs );
return $row['aw_category_id'];
}
function checkIfThumbExists( $thumb )
{
//$exists = ( file_exists( $img_src_thumb ) ) ? true : false;
//echo $exists;
//$exists = ( is_file( $img_src_thumb ) ) ? true : false;
//echo $exists;
//$AgetHeaders = #get_headers( $img_src_thumb );
//$exists = ( preg_match( "|200|", $AgetHeaders[0] ) ) ? true : false;
//echo $exists;
//$header_response = get_headers($img_src_thumb, 1);
//$exists = ( strpos( $header_response[0], "404" ) !== false ) ? false : true;;
//echo $exists;
$handle = #fopen($thumb, 'r');
$exists = (strpos($handle, "Resource id") !== false) ? true : false;
if( $exists )
{
$size = getimagesize( $thumb );
if( $size[3] == 'width="214" height="214"')
{
$exists = true;
} else {
$exists = false;
}
}
return $exists;
}
?>
Try replacing line 121 with the following:
$handle = #file_get_contents($thumb);
$handle = #fopen($thumb, 'r');
$handle not is string
The error is clear. Read manual of stropos()
It need to take a string in parameter, but in you case you set there one source($handle = #fopen($thumb, 'r');) and one string("Resource id")
Use file_get_contents, as example.
fopen returns a resource and strpos expects the first parameter to be a string.
You may use file_get_contents instead, but are you sure you want to check the binary data of a image?
$data = file_get_contents($thumb);
I don't know what are you trying to do with this line, but if you want to weather the file exists or not, i recommend you to use the native PHP functión file_exists, that gives you the chance to check if the file exists or not:
$exists = file_exists($thumb)
Here is PHP reference.
http://es1.php.net/manual/es/function.file-exists.php
As mentioned in other answers you are giving strpos a file handle or 'resource', which is wrong.
However, it looks like you want to test is if the file exists so I would simply do:
$handle = #fopen($thumb, 'r');
if($handle)
{
// File exists
}
else
{
// File doesn't exist
}
As fopen() will return a pointer (resource) if the file can be opened, else false if not.
file_get_contents() looks like the wrong option as it appears you are trying to open and image, so why would you want to search the binary for a string.
I am trying to generate multiple (in cluster) pdf reports using fpdf in a single click in a php form.
The test_center is the cluster of separate reports. When the submit button is clicked, it will call the php file of fpdf. And my codes aren't working yet.
So far in my php:
<?php
$program="select distinct test_center from sa_sase_result where school_year = '$content' ";
$prog=mysql_query($program);
while($row = mysql_fetch_array($prog))
{
echo '<option>' .$row['test_center'] . '</option>';
}
$message = null;
if($_SERVER["REQUEST_METHOD"] == "POST") {
if(!isset($_POST['depchair'])) {
} else if($_POST['depchair']=="") {
} else {
$input_depchair = addslashes($_POST['depchair']);
$input_depchair = addslashes($_POST['depchair']);
$pro_email="select control_no from sa_student_infoe y where y.test_center = '$input_depchair'";
$pro_address=mysql_query($pro_email);
$address = mysql_result($pro_address, 0);
}
}
?>
EDIT: Here's the generate_pdf.php file.
<?php
require('fpdf/fpdf.php');
mysql_connect("localhost", "root", "1234") or die(mysql_error());
mysql_select_db("final") or die(mysql_error());
$query = "SELECT * FROM sa_student_infoe, sa_student_edubg, sa_sase_result, sa_accounts";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
$control_no[] = $row['control_no'];
$surname[] = $row['surname'];
$fname[] = $row['fname'];
$mname[] = $row['mname'];
$app_no[] = $row['activation_code'];
$schoolyear[] = $row['schoolyear'];
$schl[] = $row['high_school'];
$schl_ad[] = $row['address_school'];
$apt[] = $row['aptitude'];
$mth[] = $row['math'];
$lng[] = $row['language'];
$sci[] = $row['science'];
$totgrd[] = $row['total_grade'];
$sx[] = $row['sex'];
}
$ctrl_no = array_shift( $control_no );
$sname = array_shift( $surname );
$firstname = array_shift( $fname );
$midname = array_shift( $mname );
$appno = array_shift( $app_no );
$schyear = array_shift( $schoolyear );
$school = array_shift( $schl );
$school_ad = array_shift( $schl_ad );
$aptitude = array_shift( $apt );
$math = array_shift( $mth );
$lang = array_shift( $lng );
$science = array_shift( $sci );
$gr = array_shift( $totgrd );
$sex = array_shift( $sx );
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','', 12);
$pdf->Cell(0, 0,'Mindanao State University', 0, 1, 'C');
$pdf->Cell(0, 10,'System Admission and Scholarship Examination (SASE)', 0, 1, 'C');
$pdf->Cell(0, 20,'REPORT OF RATING', 0, 1, 'C');
$pdf->Cell(30,5,'Control No:');
$pdf->Cell(100,5,$ctrl_no);
$pdf->Cell(30,5,'School Year:');
$pdf->Cell(-160,5,$schyear);
$pdf->Cell(30,15,'Activation Code:');
$pdf->Cell(10,15,' ' . $appno);
$pdf->Cell(50,40,$sname);
$pdf->Cell(50,40,$firstname);
$pdf->Cell(-120,40,$midname);
$pdf->Cell(15,50,'____________________________________________________________________');
$pdf->Cell(50,60,'LASTNAME');
$pdf->Cell(50,60,'FIRSTNAME');
$pdf->Cell(-50,60,'MIDDLENAME');
$pdf->Cell(-65,90,$school);
$pdf->Cell(67,100,'____________________________________________________________________');
$pdf->Cell(-15,110,'SCHOOL');
$pdf->Cell(-52,140,$school_ad);
$pdf->Cell(57,150,'____________________________________________________________________');
$pdf->Cell(-25,160,'SCHOOL ADDRESS');
$pdf->Cell(.1,190,'--------------------------------------------------------------------');
$pdf->Cell(-35,200,'--------------------------------------------------------------------');
$pdf->Cell(17,230,'AP(30):');
$pdf->Cell(18,230,$aptitude);
$pdf->Cell(17,230,'LU(80):');
$pdf->Cell(18,230,$lang);
$pdf->Cell(17,230,'MA(40):');
$pdf->Cell(18,230,$math);
$pdf->Cell(17,230,'SC(30):');
$pdf->Cell(18,230,$science);
$pdf->Cell(18,230,'GR(180):');
$pdf->Cell(-300,230,$gr);
$pdf->Cell(-10,260,'SEX:');
$pdf->Output("pdf_reports/SASE_report_rating/".$ctrl_no.".pdf", "F");
?>
js:
$("#id_of_generate_it_button").click(function () {
var N = 10;// ten pdf files will be generated and stored to the disk
for (i = 0; i < N; i++) {// 'the loop' -- walk thru all parallel generation processes connected to the event
parameter = N;// just to definite each single generated file
$.get("generate.php?q=parameter", function (data) {// start the ajax process to generate single document
// ?q=parameter i wrote just for passing to the php file some dependent parameter for each single file
// pdf #i generated
});
}// end for parallel generating N pdf files to the disk
});//end click
in generate.php:
$query = "SELECT * FROM sa_student_infoe, sa_student_edubg, sa_sase_result, sa_accounts WHERE some_field = ' . $_REQUEST['q'] . '";// single record from all
How is that possible to show sphinx search result via PHP
i have installed sphinx and configured but i am unable to get the result via PHP
Check the Sphinx Library : Sphinx Documentation
The Below Code Is Used To Get The Full Content From Sphinx Search Result
Now Currently We Need To Give The Id In $SQL line
<?php
echo "Welcome To Sphinx Search Site </br>";
$q = "html";
$sphx = sphinx_search("html", 0, 20);
$sphx['122'];
$ids = 122;
$sql = "SELECT post_title , post_content FROM wp_posts WHERE ID = '122'";
db();
if( !($r = mysql_query($sql)))
die("[MYSQL]".mysql_error() . mysql_errno() );
$max = $sphx['total'];
$num_rows = $sphx['docs'];
echo "<b>Displaying {$num_rows} results of {$max}</b><br /><br />";
while($row = mysql_fetch_assoc($r) ) {
echo "{$row['post_title']} <br />{$row['post_content']}<br /><hr />";
}
mysql_free_result($r);
/*
* SPHINX Search
*/
/*
* Search sites by Keywords using sphinx; with an option to search sites tags only
* #param string $q te keyword
* #param int $i id of the first result to return
* #param int $max max results to return
* #param bollen $url set to true to return matches from the 'url' column only
*
* #return string $ids comma seperated list of ids
*/
function sphinx_search($q, $i, $limit, $post_type=true){
require_once 'sphinxapi.php';
$ids = '33500';
$cl = new SphinxClient();
$cl->SetServer( "192.168.0.89" , 9667);
$cl->SetMatchMode( SPH_MATCH_EXTENDED );
$cl->SetSortMode ( SPH_SORT_RELEVANCE );
$cl->SetFieldWeights(array('post_title' => 300));
$cl->SetLimits( $i , $limit);
$q = $cl->EscapeString( $q);
//search url only
$q = $post_type ? "#post_type {$q}" : $q;
$result = $cl->Query( $q, 'sites sitesDelta' );
if ( $result === false )
error_log( '[SPHINX]Query failed: ' . $cl->GetLastError() );
elseif ( $cl->GetLastWarning() )
error_log( '[SPHINX]WARNING: ' . $cl->GetLastWarning() );
if ( !empty($result["matches"]) ){
foreach ( $result["matches"] as $doc => $docinfo )
$ids .= "$doc,";
$ids = substr( $ids, 0, -1 );
}else
return false;
return array( 'ids' => $ids, 'total' => $result['total'], 'docs' => count($result["matches"]) );
}
/*
* Connect to MySQL
*/
function db(){
if( !empty($GLOBALS['db']) ) return true;
if( !$GLOBALS['db'] = mysql_connect('localhost', 'root', '' ) ) {
die("[MYSQL]".mysql_error() . mysql_errno() );
}
elseif(!mysql_select_db('sphinxiirmulti')) {
die("[MYSQL]".mysql_error() . mysql_errno() );
}
}
?>