我想帮助你,因为我被困在这里:
SQL:
$testEvents = $db->prepare("SELECT * FROM events WHERE str_to_date(concat(`eventDate`, ' ', `time`), '%d-%m-%Y %H:%i')"); $testEvents ->execute();PHP:
<?php while ( $test = $testEvents->fetch(PDO::FETCH_ASSOC) ) { if( ! is_numeric($test['eventName'] && is_numeric($test['teamA']) && is_numeric($test['teamB']))) { echo $test['eventName']; echo "<br>"; } } ?>我的目标是尝试像这样做:
数据库映像
示例:如果eventName 不是 数字,并且teamA和teamB 不为NULL ,则显示eventName数据。
和
如果teamA和teamB 不是 数字 , eventName 是数字,则显示teamA和teamB
图像 说明 : 说明
I would like your help because I'm stuck on here:
SQL:
$testEvents = $db->prepare("SELECT * FROM events WHERE str_to_date(concat(`eventDate`, ' ', `time`), '%d-%m-%Y %H:%i')"); $testEvents ->execute();PHP:
<?php while ( $test = $testEvents->fetch(PDO::FETCH_ASSOC) ) { if( ! is_numeric($test['eventName'] && is_numeric($test['teamA']) && is_numeric($test['teamB']))) { echo $test['eventName']; echo "<br>"; } } ?>My target is try to do like:
Database image
Example: If eventName IS NOT a number and teamA & teamB ARE NOT NULL , show eventName data.
AND
If teamA & teamB ARE NOT a number and eventName IS a number, show teamA and teamB
EXPLANATION IN IMAGE: Explanation
最满意答案
除了你奇怪的数据库设计......以回答你的问题,你可以试试这个...
我编写了一些测试数据来模拟你的数据库
$data = [ [ 'eventName'=>'1', 'teamA'=>'Magallanes', 'teamB'=>'Caracas', 'eventDate'=>'17-11-2016', 'eventTime'=>'11:11' ], [ 'eventName'=>'Manana', 'teamA'=>'123', 'teamB'=>'123', 'eventDate'=>'17-11-2016', 'eventTime'=>'12:12' ] ];然后测试了代码来执行你的循环...你在正确的轨道但显然你只是放弃....
foreach($data as $test) { if( ! is_numeric($test['eventName']) && is_numeric($test['teamA']) && is_numeric($test['teamB'])) { echo $test['eventName']; echo " "; echo $test['eventDate']; echo " "; echo $test['eventTime']; echo "<br>"; } else if (is_numeric($test['eventName']) && ! is_numeric($test['teamA']) && ! is_numeric($test['teamB'])) { echo $test['teamA']; echo " x "; echo $test['teamB']; echo " "; echo $test['eventDate']; echo " "; echo $test['eventTime']; echo "<br>"; } }结果
Magallanes x Caracas 17-11-2016 11:11 Manana 17-11-2016 12:12根据需要交换和更改内容。
Well apart from your strange database design... to answer your question you can try this...
I made up some test data to simulate your database
$data = [ [ 'eventName'=>'1', 'teamA'=>'Magallanes', 'teamB'=>'Caracas', 'eventDate'=>'17-11-2016', 'eventTime'=>'11:11' ], [ 'eventName'=>'Manana', 'teamA'=>'123', 'teamB'=>'123', 'eventDate'=>'17-11-2016', 'eventTime'=>'12:12' ] ];Then tested out the code to perform your loop... You were on the right track but obviously you just gave up....
foreach($data as $test) { if( ! is_numeric($test['eventName']) && is_numeric($test['teamA']) && is_numeric($test['teamB'])) { echo $test['eventName']; echo " "; echo $test['eventDate']; echo " "; echo $test['eventTime']; echo "<br>"; } else if (is_numeric($test['eventName']) && ! is_numeric($test['teamA']) && ! is_numeric($test['teamB'])) { echo $test['teamA']; echo " x "; echo $test['teamB']; echo " "; echo $test['eventDate']; echo " "; echo $test['eventTime']; echo "<br>"; } }The Results
Magallanes x Caracas 17-11-2016 11:11 Manana 17-11-2016 12:12Swap and change things as you require.
更多推荐
发布评论