Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Wyswietlanie textu o rozmiarze czcionki pobranej z formy
qubert
post 11.04.2012, 12:49:44
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 11.04.2012

Ostrzeżenie: (0%)
-----


Witam wszytskich forumowiczow!

Jest to moj 1 post a przygode z PHP zaczelem w styczniu takze wybaczcie jesli jest to blachy problem.

Na zadanie domowe musze zrobic 2 strony na pierwszej wybieram miesiac, rozmiar czcionki i ilosc zapytan do bazy. Czyli droga zwraca np:"pokaz" 2 zamowienia z lutego czcionka 2.

Do momentu wyswietlania z bazy wszystko dziala. Zmienna $font posiada wartosc z formularza ale nie wiem jak to pokazac loopie while.

Ponizej jest moj kod - ale chyba print screen najlepiej pokazuje o co chodzi.

CODE
<?php

mysql_connect("127.0.0.1", "root", "") or die("Could not connect : " . mysql_error());
mysql_select_db("orders") or die("Could not select database");


$month = $_GET['month']; //-- month passed from previous page
$font = $_GET['font']; //-- font passed from previous page
$order = $_GET['order']; //-- number of orders passed from previous page
$i = 0; //-- loop counter


//--converting names to numbers

$num = $month;

switch ($num){
case 'January': $num = 01; break;
case 'February': $num = 02; break;
case 'March': $num = 03; break;
case 'April': $num = 04; break;
case 'May': $num = 05; break;
case 'June': $num = 06; break;
case 'July': $num = 07; break;
case 'August': $num = 8; break;
case 'September': $num = 9; break;
case 'October': $num = 10; break;
case 'November': $num = 11; break;
case 'December': $num = 12; break;
}

//--connecting mysql join 2 table results
$query = "select * from orders o join customer c on o.customer_id = c.customer_id where month(order_date)='$num'";
$result = mysql_query($query) or die("Query Error ".mysql_error());

//echo $query;

?>


<head>
<meta charset="utf-8" />
<title>WebFund</title>
<meta name="A1" content="Assignment1" />
</head>
<body>

<!-- Printing table -->
<table width="400" border="0">
<tr>
<td><font size="<?php print $font;?>">Month:</td>
<td><font size="<?php print $font;?>"></td>
<td><font size="<?php print $font;?>"> </td>
<td><font size="<?php print $font;?>"> </td>
</tr>
<tr>
<td><font size="<?php print $font;?>">Order_id</td>
<td><font size="<?php print $font;?>">Customer</td>
<td><font size="<?php print $font;?>">Order_date</td>
<td><font size="<?php print $font;?>">Order_item</td>
</tr>

<?php
//error_reporting(E_ALL);

/*
<font size="<?php print $font;?>"> - from above didn't work also tried i.e.
print '<tr><td><font size="<?php print $font;?>">'.$record[order_id].'</td>';
*/


while ($i<$order){
$record = mysql_fetch_array($result, MYSQL_ASSOC);

print '<tr><td><style= font-size:'.$font.'>'.$record[order_id].'</td>';
print '<td><style= font-size:'.$font.'>'.$record[firstname].$record[surname].'</td>';
print '<td><style= font-size:'.$font.'>'.$record[order_date].'</td>';
print '<td><style= font-size:'.$font.'>'.$record[order_item].'</td></tr></style>';
$i++;
}
echo 'value of font is '.$font; //--shows $font value is correct

?>

</table>
</font>

</body>
</html>




Ten post edytował qubert 11.04.2012, 12:51:25
Go to the top of the page
+Quote Post
maniana
post 11.04.2012, 13:09:06
Post #2





Grupa: Zarejestrowani
Postów: 207
Pomógł: 44
Dołączył: 18.05.2007

Ostrzeżenie: (0%)
-----


Samo przetwarzanie danych z bazy danych za pomocą while wygląda tak:
Cytat
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) {
// zawartość pętli...
}

Jadnak przy wizualizacji wyników skorzystaj z css, będzie więcej możliwości formatowania tekstu. Przykład:
Cytat
<table width="400" border="0" class="size<?php echo $font;?>">
<tr>
<td>>Month:</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Order_id</td>
<td>Customer</td>
<td>Order_date</td>
<td>Order_item</td>
</tr>
<?php
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)){
print '<tr><td>'.$record['order_id'].'</td>';
print '<td>'.$record['firstname'].$record['surname'].'</td>';
print '<td>'.$record['order_date'].'</td>';
print '<td>'.$record['order_item'].'</td></tr>';
}
?>
</table>

i do tego css:
Cytat
table.size1 td {
font-size:11;
}
table.size2 td {
font-size:13;
}
table.size3 td {
font-size:15;
}
Go to the top of the page
+Quote Post
camikazee
post 11.04.2012, 13:11:31
Post #3





Grupa: Zarejestrowani
Postów: 171
Pomógł: 18
Dołączył: 17.04.2006
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Pierwsza sprawa, zamiast switchem rozpoznawać numer danego miesiąca lepiej wrzucić to do tablicy
  1. $miesiac = array('January' => '01', 'February' => '02', 'March' => '03'); //itd

druga sprawa jak masz <td><style... powinno być <td style="font-size: xx">


--------------------
www.fachoweuslugi.pl | www.zlec-usluge.pl | www.pokazsie.pl
Go to the top of the page
+Quote Post
qubert
post 11.04.2012, 13:17:41
Post #4





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 11.04.2012

Ostrzeżenie: (0%)
-----


maniana - Dziekuje Slicznie jest jak trzeba!

camikazee - gdybym tylko to wiedzial wczesniej napewno bylo by latwiej - Dzieki!

Ten post edytował qubert 11.04.2012, 13:21:38
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 6.07.2025 - 01:30