Sunday, 15 July 2012

php - my code works fine with two selects but Im trying to use just one -



php - my code works fine with two selects but Im trying to use just one -

i have table "shedules" maintain 2 records(my shedules saved in pdf format).

one record relative 1st year shedule, record like:

(id,pdf,year) (1,../uploads/shedules/1st_year.pdf, 1st_year)

my othe record like:

(id,pdf,year) (2,../uploads/shedules/2nd_year.pdf, 2nd_year)

my shedules updated every week, can updated without specific order, can first updated schedule of first year or sec year.

and in form, update schedules, have 2 links show current schedules of each year.

and want show on link "see schedule 1st year" schedule pdf of 1st year, , want show on link "see schedule 2nd year" schedule pdf of 2nd year.

do know how can without doing 2 selects?? did 2 selects im trying using one.

i trying using "order year asc" dont works fine because user update shedules can insert first 1st year or 2nd year...

<?php $readshedules = $pdo->prepare("select pdf schedules order year asc"); $readshedules->execute(); $result = $readshedules->fetch(pdo::fetch_assoc); echo '<div>'; echo '<a style="margin-right:10px;" href="../uploads/pdfs/'.$result['pdf'].'">see schedules 1st year</a>'; echo '<a href="../uploads/pdfs/'.$result['pdf'].'">see schedule 2nd year</a>'; echo '</div><!--viewcapa-->'; ?>

it sounds you're looking retrieve multiple rows database. if that's case i'd point toward pdo fetchall method, retrieves matches query instead of fetch retrieves first one.

something along these lines:

$results = $readshedules->fetchall(pdo::fetch_assoc); echo '<div>'; foreach( $results $result ) { echo '<a style="margin-right:10px;" href="../uploads/pdfs/'.$result['pdf'].'">see schedules '.$result['year'].'</a>'; } echo '</div><!--viewcapa-->';

php

No comments:

Post a Comment