Sponsored Content
Full Discussion: php to perl help
Top Forums Shell Programming and Scripting php to perl help Post 302576852 by Joey12 on Sunday 27th of November 2011 12:07:05 AM
Old 11-27-2011
php to perl help

Hey guys,

I have some php code that I am trying to convert to perl code and I am having some probelms. I am posting my php to show what I am having difficulty converting. I know all the $_GET's will not work but I have taken care of that in my code. My main issue is with the bind_results, is there a similar function I can use in perl for that? I also want to print all these variables in TT2, so what would I have to change in my fetch() to allow me to do that?

Code:
$number_searched=0; 
$searchquery=$_GET['phrase']; 
$offset=0; 
$page_result=10; 
$number_pages=0;
$first_page=($_GET['page']==0)?1:$_GET['page']; 
$choice=$_GET['book']; 



if ($_GET['book']=='E')
{
$state ="";
}
else if ($_GET['book']=='O')
{
$state="AND bsect='O'";
}
else if ($_GET['book']=='N')
{
$state="AND bsect='N'";
}
else if ($choice!=NULL)
{
$state = "AND $choice=bnum";
}



//get the results for the searched word 
$row_search=$mysqli->query("SELECT bsect, bname, bnum, cnum, vnum, vtext, MATCH(bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) AS relevance FROM kjv WHERE MATCH (bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) $state ORDER BY relevance");
$number_searched=$row_search->num_rows;

//round the results 
$number_pages=ceil($number_searched/$page_result);
    
//gets the starting row number
$offset=(($first_page-1)*$page_result);
    
//starts at the offset and gets the $page_results    
$limit="LIMIT $offset, $page_result";



?>

<?php

//this will show the results on the page
    if ($_GET['count_only']!=1)
    {
        if ($_GET['phrase']!=NULL)
        {
                
            $text_r=$mysqli->prepare("SELECT @rownum:=@rownum+1 rownum, bsect, bname, bnum, cnum, vnum, vtext, MATCH(bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) AS relevance FROM (SELECT @rownum:=0) row, kjv WHERE MATCH (bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) $state ORDER BY relevance $limit");
            
            $text_r->execute();
            
            $text_r->bind_result($rownum, $bsect, $bname, $bnum, $cnum, $vnum, $vtext, $match);
            
            echo("<div id=\"searchrez\">");
            
                while ($text_r->fetch())
                {
                    $rownum+=$offset; 
                    echo("<h3>$bname $cnum:$vnum</h3>");
                    echo("<ul><li>$vtext</li></ul>");
                }
            echo("</div>");
        }
    }
?>

 

10 More Discussions You Might Find Interesting

1. Web Development

php and perl on apache server

I'm having problems opening php and perl files on Apache. The server hasn't any association with those type of files by default and a window asking to choose a program to open them popups from the browser. How can I do to process them with the browser Thanks in advance. (1 Reply)
Discussion started by: capibolso
1 Replies

2. Shell Programming and Scripting

geting user input from php and using perl for execution

I am using festival speech synthesis system and I would like to allow user input in a browser. This will be taken by a php page which is then supposed to pass the input text to a perl script. The perl script should pass this text to the festival engine by executing a unix command. this in turn... (2 Replies)
Discussion started by: wairimus
2 Replies

3. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

4. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

5. Shell Programming and Scripting

calling a php file from perl script..

Hi am new to perl script .. i need some useful tutorials links to learn perl script.. and a sample script to call a php file from perl script.. thanks.. (3 Replies)
Discussion started by: senkerth
3 Replies

6. UNIX for Advanced & Expert Users

perl and HP-UX : instmodsh in combination with software depot : update inventory for installed Perl

we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module i can't find with instmodsh in the inventory for installed Perl modules. - i have learned of using instmodsh command : i find out what modules are already installed on my system. ... (0 Replies)
Discussion started by: bora99
0 Replies

7. Shell Programming and Scripting

PHP code to Perl plx

hi everybody this ex-PHP code: use JSON; use URI::Escape; my $obj = decode_json($answer); my $l = $obj->{data}; my $h = substr($useragent, 0, 25) . $fuid01 . 'I keep watch over you ;)'; my $str = ""; for (my $g = 0; $g < length($l); $g++){ $str.= chr(ord($l) ^ ord($h)); } print... (2 Replies)
Discussion started by: tip78
2 Replies

8. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

9. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

10. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies
MYSQLI_MULTI_QUERY(3)							 1						     MYSQLI_MULTI_QUERY(3)

mysqli::multi_query - Performs a query on the database

       Object oriented style

SYNOPSIS
bool mysqli::multi_query (string $query) DESCRIPTION
Procedural style bool mysqli_multi_query (mysqli $link, string $query) Executes one or multiple queries which are concatenated by a semicolon. To retrieve the resultset from the first query you can use mysqli_use_result(3) or mysqli_store_result(3). All subsequent query results can be processed using mysqli_more_results(3) and mysqli_next_result(3). PARAMETERS
o $ link -Procedural style only: A link identifier returned by mysqli_connect(3) or mysqli_init(3) o $query - The query, as a string. Data inside the query should be properly escaped. RETURN VALUES
Returns FALSE if the first statement failed. To retrieve subsequent errors from other statements you have to call mysqli_next_result(3) first. EXAMPLES
Example #1 mysqli::multi_query example Object oriented style <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } $query = "SELECT CURRENT_USER();"; $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5"; /* execute multi query */ if ($mysqli->multi_query($query)) { do { /* store first result set */ if ($result = $mysqli->store_result()) { while ($row = $result->fetch_row()) { printf("%s ", $row[0]); } $result->free(); } /* print divider */ if ($mysqli->more_results()) { printf("----------------- "); } } while ($mysqli->next_result()); } /* close connection */ $mysqli->close(); ?> Procedural style <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } $query = "SELECT CURRENT_USER();"; $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5"; /* execute multi query */ if (mysqli_multi_query($link, $query)) { do { /* store first result set */ if ($result = mysqli_store_result($link)) { while ($row = mysqli_fetch_row($result)) { printf("%s ", $row[0]); } mysqli_free_result($result); } /* print divider */ if (mysqli_more_results($link)) { printf("----------------- "); } } while (mysqli_next_result($link)); } /* close connection */ mysqli_close($link); ?> The above examples will output something similar to: my_user@localhost ----------------- Amersfoort Maastricht Dordrecht Leiden Haarlemmermeer SEE ALSO
mysqli_query(3), mysqli_use_result(3), mysqli_store_result(3), mysqli_next_result(3), mysqli_more_results(3). PHP Documentation Group MYSQLI_MULTI_QUERY(3)
All times are GMT -4. The time now is 02:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy