-
Posts
24,389 -
Joined
-
Last visited
-
Days Won
803
Posts posted by Barand
-
-
Does
position: fixed;
work?
-
Change
function PDF($orientation='P', $unit='mm', $size='A4')
to
function __construct($orientation='P', $unit='mm', $size='A4')
Giving the constructor function the same name as the class is very PHP version 4 and you can't get away with it any more.
You probably have to make the same amendment in your FPDF class also if it's an old version.
-
First off, I'd put just the connection code in the included file. You also need to add a few options when connecting with PDO. EG
$db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
Put the query and result processing in the main file.
$userQuery = $db->prepare(" SELECT idUsers, uidUsers, emailUsers, pwdUsers, premium FROM users WHERE idUsers =:user_id "); $userQuery->execute(['user_id' => $_SESSION['user_id']]); while ($user = $userQuery->fetchObject()) { echo $user->premium ? '<img src="../../img/premium.png" alt="Swiftify+">' : '<img src="../../img/swiftify.png" alt="Swiftify+">' ; echo '<br>'; }
-
Sorry, but I can't see how you get different results from table2 for each of the table1 records. I must be missing something.
Stick around and maybe one of the others here can see what's going on and offer help.
-
The code you posted only fetches the first record. I don't see how it can behave as you describe.
-
And what happens when you run it?
-
Those two queries are totally unrelated, so, for each record in the first set of results you produce an identical set of results from the second query.
Either confirm that is what you want to do or tell us what is you really want to do - or i'm giving up.
-
I still have no idea what you are trying to do.
Instead of showing your attempts, why don't you show
- the original two queries, the one that doesn't appear in a loop and the second one which does.
- some sample data
- expected results
-
Are those the two queries you mentioned, or two of your attempts at combining the queries.
Your first references Visits.Va2 yet there is no mention of a Visits table.
You also mention LEFT/Right JOIN and UNION but they seem to be absent too, as is any kind of JOIN.
Why is the second query being run in a loop?
In other words, can you provide a better description of what you are trying to, preferably with the table structures.
-
Here's an example which uses the "sakila" film database, displaying film titles for the selected guidance rating
<?php include 'db_inc.php'; // DATABASE $db = pdoConnect('sakila'); // CONNECTION STUFF // // PROCESS AJAX REQUESTS // if (isset($_GET['ajax'])) { $res = $db->prepare("SELECT title FROM film WHERE rating = ? ORDER BY title "); $res->execute( [ $_GET['rating'] ] ) ; $films = $res->fetchAll(); exit(json_encode($films)) ; } // // GET LIST OF RATINGS FOR SELECTION // $res = $db->query("SELECT DISTINCT rating FROM film ORDER BY rating "); $rating_list = ''; foreach ($res as $r) { $rating_list .= '<li class="w3-light-gray w3-hover-blue">'.$r['rating'].'</li>'; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="creation-date" content="05/10/2019"> <title>Movies by Rating</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $().ready( function() { $("li").click(function() { var rating = $(this).html() $.get( "" , {"ajax":1, "rating":rating} , function (response) { $("#search-results").html("") $.each(response, function(k,v) { $("#search-results").append(v.title+"<br>") }) } , "JSON" ) }) }) </script> </head> <body> <h1>Films by Rating</h1> <div class="w3-ul w3-card-4 w3-margin w3-hoverable" style="width:25%; float:left; position: fixed"> <?=$rating_list?> </div> <div id="search-results" class="w3-content w3-margin w3-padding "style="float:right; width:70%;"> </div> </body> </html>
-
Get your searchValue() function to call the ajax request.
-
3 hours ago, Barand said:
if ( !isset($_SESSION['defaultseasonid_']) || !isset($_SESSION['defaultmatchtypeid_']) || !isset($_SESSION['defaultlanguage_']) )
For the sake of completeness, an alternative way to write this is
if (!isset($_SESSION['defaultseasonid_'], $_SESSION['defaultmatchtypeid_'], $_SESSION['defaultlanguage_']))
-
1 minute ago, AlMch said:
now only the season drop-down is working.
That's the only one that you check with isset(). Should be
if ( !isset($_SESSION['defaultseasonid_']) || !isset($_SESSION['defaultmatchtypeid_']) || !isset($_SESSION['defaultlanguage_']) )
but the ?? method is a lot simpler.
-
1
-
-
As of PHP 7.0 you could replace this code...
if(!session_is_registered('defaultseasonid_') || !session_is_registered('defaultmatchtypeid_') || !session_is_registered('defaultlanguage_')) { $_SESSION['defaultseasonid_'] = $pdata['DefaultSeasonID']; $_SESSION['defaultmatchtypeid_'] = $pdata['DefaultMatchTypeID']; $_SESSION['defaultlanguage_'] = $pdata['DefaultLanguage']; $defaultseasonid = $_SESSION['defaultseasonid_']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_']; $defaultlanguage = $_SESSION['defaultlanguage_']; } else { $defaultseasonid = $_SESSION['defaultseasonid_']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_']; $defaultlanguage = $_SESSION['defaultlanguage_']; }
with ...
$defaultseasonid = $_SESSION['defaultseasonid_'] ?? $pdata['DefaultSeasonID']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_'] ?? $pdata['DefaultMatchTypeID']; $defaultlanguage = $_SESSION['defaultlanguage_'] ?? $pdata['DefaultLanguage'];
"??" is the "null coalesce" operator, so
$a = $b ?? $c ?? $d;
will set $a to the first of the three values that is not null.
-
1
-
-
It's $_SESSION. not $SESSION
Have you called session_start() at the top of the script?
-
-
Try reading the manual (session_is_registered) . After all, that's why they wrote it.
-
if the purpose is to find the class given the sectional# then it would be easier if the array were inverted...
<?php foreach (range(1,16) as $sect) $sectional_class[$sect] = 4; foreach (range(17,32) as $sect) $sectional_class[$sect] = 3; foreach (range(33,48) as $sect) $sectional_class[$sect] = 2; foreach (range(49,64) as $sect) $sectional_class[$sect] = 1; echo $sectional_class[25]; //--> 3 ?>
or you can get them direct form the database without using array to look them up
SELECT t.team_name , s.sectional_id , c.class_id FROM team t JOIN sectional_team st USING (team_id) JOIN sectional s USING (sectional_id) JOIN class c USING (class_id) WHERE season = ?
-
1
-
-
That array structure is held within the database
-
10 minutes ago, Jim R said:
The code would be stagnant. We know every year in basketball, teams in sectional 1-16 are 4A. What we don't know is which class or sectional every team is in from year to year.
In which case you have in intermediate file to record, each season, which sectional a team is in
-
Are you saying you would prefer to rewrite your code every year instead of just changing the data?
-
1 hour ago, Jim R said:
So I have a Schools table that has a BSectionals column (B = basketball), and I'll eventually have a column for each sport.
Adding columns for each sport is not the way to design database tables.
From what you described above,
- Each sport has several classes
- Each class has several sectionals
- Each sectional has several teams
- Each school has several teams(sports)
so your data should reflect this structure
-
... and why do you want 16 keys for the same value?
-
You could do it the same way you did it 4 hours ago
Call db stored procedure when button is clicked
in PHP Coding Help
Posted · Edited by Barand
The syntax to run a stored procedure from PHP is as follows (where $db is the database connection)...
or, if the procedure requires parameters...